please advice - what's wrong with my syntax ? ( should not print the "bad interface " )
remark - I work with bash shell
ETH_NAME=eth0 ( or any other as eth1 or eth2 .... )
echo $ETH_NAME
eth0
[ $ETH_NAME != eth[0-9] ] && echo bad interface
Use the
[[ ... ]]
compound command which can do pattern matching with!=
Or use the standard (POSIX sh)
case
statement instead of ksh's[[...]]
(also found in bash and zsh).Note that it will say that eth10 is a bad interface.
You could instead do
(note that network interfaces names including ethernet ones are not limited to
ethx
).My favorite way of doing that matching is
case…esac
:since it's fast and rather portable (doesn't require using
bash
). I can't say that subset of regexps available forcase
is a rich one, but often it's sufficient.