Reputation: 9621
I have simple bash script find.sh for finding the files
==>cat find.sh
echo $1
find -name $1
but it is not taking the correct arguments sometimes, instead it takes the fixed argument
Eg
find.sh 'ECSv2_P_TCP_FUNC_060*'
ECSv2_P_TCP_FUNC_060 ECSv2_P_TCP_FUNC_060.backup
Here though i have passed 'ECSv2_P_TCP_FUNC_060*' it has taken ECSv2_P_TCP_FUNC_060 ECSv2_P_TCP_FUNC_060.backup these as arguments.
Why does this happen? And how to avoid this?
Upvotes: 0
Views: 191
Reputation: 1461
You need to protect the * character from shell expansion inside the script as well:
echo "$1"
find . -name "$1"
(Edited to include the current directory as argument for find.)
Upvotes: 5
Reputation: 212218
Your script is indeed taking the argument, but the script is expanding the * before passing it to echo and find is reading the argument and interpreting the *. (Actually, find is probably bombing because the first arguemnt should be a directory. eg, 'find . -name $1')
Upvotes: 1