i have been trying to get a script working that can take in more than one option using getopt. But for some reason, even when i type in a covered option, it skips directly to my error message of "no match." Any ideas of what might be wrong?
set - 'getopt frd*: $*'
for i in $*
do
case $i in
-f) rm -f;;
-r) rm -r;;
-d) rm -d;;
"") rm;;
*) echo "no match" ;
exit;;
esac
done
There are two quotes here and they are both backquotes, not single quotes. You might need to put frd* in double quotes if you have a screwy file that matches that template. Then you need:
for i in $*
No quotes here!
Change
-f) rm -f
to
-f) echo rm -f
until you get this working. Same for the other rm's. rm is dangerous.
After the "do", put "echo i = $i" so you can see what is happening.
it works! thanks. it seem that in the loop's last iteration, i = -- and so the error message prints every time because I did not have a case for that. After adding the case the problem went away.