William William - 1 year ago 53
Bash Question

Shellscript Newbie - Issue with Wildcards & Arguments in a Script

As the title suggests I'm just starting out with shellscript so don't really know much about it!

My question is this - why does the following wildcard work in bash

mv *.txt /root/Dustbin

But my shellscript file only moves one .txt file and not all? I install the script and call it as follows

del *.txt

This is the script:

#sh scriptname del

mv -u $1 /root/Dustbin


Hope my question makes sense

Thanks in advance for any help

Answer Source

$1 is the first argument of the script. So even if there are multiple files matching *.txt, only the first one will be moved. If you want to move all of them, use "$@" instead:


mv -u "$@" /root/Dustbin
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download