Thread
:
[Linux bash] Why is this not working?
View Single Post
CowboyFromHell
2010-03-11 , 17:24
Posts: 17 | Thanked: 4 times | Joined on Mar 2010 @ Germany
#
14
Yep, * has its wildcard characteristic only by certain interpreters. Bash interprets it as gobuki described, as long as it's actually interpreted by bash (i.e. not escaped e.g. by \ or ''). Compare
echo *b*
and
echo "*b*"
in bash with some file with b in its name in the same directory.
Thus, fiddeling with * with some tools like
find ... -regex ... -exec ...
can be quite tricky in escaping "enough" to avoid bash interpreting it in the first step but have find interpret it for -regex but not for -exec which shall pass it to the next level of bash.........;°))
For sed and numerous other tools * is the "any number of" operator used in regular expressions ( ab*c).
Test (or the short form [...]) does not interpret or compare any regular expressions, if using = (single = is the "official" documented version but == works, too) but rather compares the strings literally.
If you want some regex functionality, try this:
my="abcd"
if [ `echo $my | grep bc` ]
then
echo "Ok"
else
echo "Not ok"
fi
Good luck!
Quote & Reply
|
CowboyFromHell
View Public Profile
Send a private message to CowboyFromHell
Find all posts by CowboyFromHell