#! /usr/bin/ksh
for arg ; do
echo testing arg = "$arg"
if [[ $arg = *[*]* ]] ; then
echo "$arg" contains at least one \*
fi
if [[ $arg = *[?]* ]] ; then
echo "$arg" contains at least one \?
fi
done
exit 0
NB, to run this you will probably need
./script one two\*
or something. If you don't escape the wildcard, the shell may expand it. If that happens, there is no way to recover the original command line.
I am writing a script that takes arguments. first check if the arguments contain wildcard (?,*) . if it contains , list it. if it doesn't contains, do something else (eg. cp it)
the problem is:
when i type
> script1 a*
the $@ contain : a, ab, aaa, abcd .....
and $1 is a, $2 is ab, $3 is aaa....
there is no such a variable is actually "a*" for me to check!!
I can turn off the 'noglob' by typing > set -o noglob
but, i can't do it IN A SCRIPT.
You already asked this question, and had it answered over here:
::merged threads - removed url::
It was also noted that the shell would replace that * with all the things it matched (if any) before sending it iff to the script, so there would not be a way to check for the presence of a "" unless it was escaped from the shell like this:
your_command a\ or
your_command 'a*'