Bash Command Line Args

by
published on
$1, $2,...first argument, second argument
$0

script filename

$$PID of bash shell
$*Values of arguments passed to the script in double quotes
$#Number of arguments
$@Values of arguments passed to the script

Here is an example script that merges pdfs using ghostscript and uses the '$@' variable:

#!/bin/bash
# pass filenames to be merged with a space in between
# $@ represents values of all the arguments passed, except the scriptname itself
# if needed you can replace $@ with $1 $2 $3 where you only have 3 files
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dAutoRotatePages=/None -sOutputFile=output.pdf $@