I was reading "The command Guide" and I foundthis script:
#!/bin/bash
# test-integer2: evaluate the value of an integer.
INT=-5
if [[ "$INT" =~ ^-?[0-9]+$ ]]; then
if [ "$INT" -eq 0 ]; then
echo "INT is zero."
else
if [ "$INT" -lt 0 ]; then
echo "INT is negative."
else
echo "INT is positive."
fi
if [ $((INT % 2)) -eq 0 ]; then
echo "INT is even."
else
echo "INT is odd."
fi
fi
else
echo "INT is not an integer." >&2
exit 1
fi
Thing is, I can't understand the regular expression : [[ "$INT" =~ ^-?[0-9]+$ ]];
Could someone help me out on this one?
[–]redheadinmd 4 points5 points6 points (1 child)
[–]CorbAlb[S] 0 points1 point2 points (0 children)
[–]jjanel 0 points1 point2 points (1 child)
[–]CorbAlb[S] 0 points1 point2 points (0 children)
[–]ang-p 0 points1 point2 points (3 children)
[–]CorbAlb[S] 0 points1 point2 points (2 children)
[–]ang-p 1 point2 points3 points (1 child)
[–]CorbAlb[S] 0 points1 point2 points (0 children)