WAF's [[ "$VAR" =~ "HI" ]]
answer here has a great bash
/ksh
solution that is probably what you are looking for, but in case somebody is looking for a portable solution, here is how to do this natively within a plain POSIX shell (the base /bin/sh
):
[ "$VAR" != "${VAR#*HI}" ]
Be careful, shell pattern syntax (aka "globbing") is different from POSIX regular expression syntax.
This compares the value of $VAR
with the ${VAR#*HI}
parameter expansion, which implements substring removal to remove anything at its beginning up to the first instance of "HI" (given VAR="OHIO"
, ${VAR#*HI}
would be remove the leading OHI
and result in just O
. VAR="Hi, I am bob"
would be unchanged).
Due to the !=
comparison, the return value will be true (0
) when the two strings differ (meaning "HI" exists in $VAR
) and false (1
) when they are the same (meaning "HI" does not exist in $VAR
).
echo "$VAR"
? – Costas Mar 04 '15 at 19:28su
and give your root password (orsudo bash
, in some Linux distributions)`, you will then be root and you should then fix the access/permission problems... – Ariel Mar 04 '15 at 19:39