Validating number in perl
Therefore, a more usual style for shell programming is this: Unless you need to modify old scripts it does not make sense to use old ksh-style regex in bash.(partially borrowed from Bash Regular Expressions | Linux Journal) Since version 3 of bash (released in 2004) bash implements They are also called POSIX regular expressions as they are defined in IEEE POSIX 1003.2.So good knowledge of them is necessary for any sysadmin.Let's say we need to establish whether variable for ip in "255.255.255.255" ".10" "400.0.0.0" ; do echo "=== testing $ip ===" if $ip =~ ^[0-2][0-9]\.[0-2][0-9]\.[0-2][0-9]\.[0-2][0-9] ; then echo "$ip Looks like a valid IP" else echo "$ip is unvalid ip" fi done' so space is the first unmatched symbol that gets into the result.
The minor differences are the treatment of escaped characters and new line character. echo $' Three form feeds \f \f \f' echo $'10 newlines \n\n\n\n\n\n\n\n\n\n' echo $'\102\141\163\150' # Bash # Octal equivalent of characters.]]
It's actually sad that AWK was not integrated into shell.for more about Perl compatible regular expression see Text processing using regex.