6.8 Passing arguments to a script
When running a script on the command line, we can pass arguments to it. Inside our script, we can use these arguments to e.g. write output to a specific directory or calculate something. There are pre-defined variables which we can use to access the command line arguments. $0
refers to the first argument on the command line - which is simply the name of the BASH script we’re executing. $1
refers to the second argument, $2
to the third, and so on.
For example, create a BASH script called “testArguments.sh” with the following content:
and execute it: