In my script, I use awk
, the options are hardcoded but the file name is not, so I have awk options $1
If I wanted a 2 files version I would do awk options $1 $2
.
How to do it for arbitrary number of files? ($1
up to "$last"
).
You can redesign your script to use "$@"
; or you can check $#
and run your commands accordingly.
Bash Reference Manual states:
$@
Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, each parameter expands to a separate word. That is,"$@"
is equivalent to"$1" "$2" …
. […] When there are no positional parameters,"$@"
and$@
expand to nothing (i.e., they are removed).
awk options "$@"
If you need to use few command line parameters that are not filenames, take a look at shift
builtin.
$#
Expands to the number of positional parameters in decimal.
Use it with some conditionals if you need to invoke different commands, depending on this number.