regex - Shell script linux, validating integer -
this code check if character integer or not (i think). i'm trying understand means, mean... each part of line, checking grep man pages, it's difficult me. found on internet. if explain me part of grep... means each thing put there:
echo $character | grep -eq '^(\+|-)?[0-9]+$'
thanks people!!!
analyse regex:
'^(\+|-)?[0-9]+$' ^ - line start (\+|-)? - optional + or - sign @ start [0-9]+ - 1 or more digits $ - line end
overall matches strings +123
or -98765
or 9
here -e
extended regex support , -q
quiet in grep command.
ps: btw don't need grep
check , can directly in pure bash:
re='^(\+|-)?[0-9]+$' [[ "$character" =~ $re ]] && echo "its integer"
Comments
Post a Comment