The *.pdf
will be expanded by the shell before executing the script, so the script won't see *.pdf
, it will see the matching filenames directly:
$ cat foo.sh
#! /bin/sh
printf "|%s|\n" "$@"
$ touch {1..10}.pdf
$ ./foo.sh 1.pdf
|1.pdf|
$ ./foo.sh *.pdf
|1.pdf|
|10.pdf|
|2.pdf|
|3.pdf|
|4.pdf|
|5.pdf|
|6.pdf|
|7.pdf|
|8.pdf|
|9.pdf|
Within a bash script, you can use "$@"
to get all the arguments passed to it, or use $1
, $2
, etc. to access the first, second, etc. argument directly.
You can just loop over all arguments with a plain for
:
for i # Or, for i in "$@"
do
echo "Processing argument $i"
done
Will output:
Processing argument 1.pdf
Processing argument 10.pdf
Processing argument 2.pdf
Processing argument 3.pdf
Processing argument 4.pdf
Processing argument 5.pdf
Processing argument 6.pdf
Processing argument 7.pdf
Processing argument 8.pdf
Processing argument 9.pdf