Iterating Over Arguments in Bash
| bashArguments can be accessed using $@
. In contrast to $*
, $@
correctly parses quoted arguments. Given the following script name args.sh
:
for var in "$@"
do
echo "$var"
done
Running this script with the following arguments yields:
sh args.sh a b "c d"
a
b
c d
Pretty useful for scraping stuff, creating conditional directories, renaming files, etc…