View Single Post
eitama's Avatar
Posts: 702 | Thanked: 334 times | Joined on Feb 2010 @ Israel.
#16
Originally Posted by CowboyFromHell View Post
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!
Thank you very much CowboyFromHell,

The example you posted works well, but when I tried to adapt it a bit to my needs, I have an odd error :

Code:
Nokia-N900-02-8:/etc/network# vi detectUsb.sh
#!/bin/sh

my=`/sbin/ifconfig`

if [ `echo $my | grep RUNNING` ]
then
        echo "Ok"
else
        echo "Not ok"
fi

Nokia-N900-02-8:/etc/network# ./detectUsb.sh
sh: Link: unknown operand
Not ok
Could you help me out on this one?
I am a big bash / sh noob.