In shell scripts you can use $1
to refer to the first argument, $2
for the second, etc. If you want to refer to all arguments (e.g. when writing a bash script that takes an arbitrary amount of arguments and passes them on to another call), you may not want to do a “$1 $2 $3 $4 ...
”.
Use $@
instead, like in this script:
$ cat welcome
#!/bin/bash
echo Hello to $@
When called, the above would produce this:
$ ./welcome the world and universe
Hello to the world and universe
Note that $@
works for both sh
and bash
.
Posted by Arne Hartherz to makandra dev (2011-07-01 13:28)