1. Home
  2. Bash
  3. Bash Tutorial
  4. Bash – Command Arguments

Bash – Command Arguments

Command Line Arguments in Bash

You can pass command line arguments to bash shell script. These are helpful to make a script more dynamic. Learn more about Bash command arguments.


$ ./myscript.sh ARG1 ARG2

You can also use special variables provided by the shell, in your script.

 Special Variable
 Variable Details
 $1 to $n
$1 is the first arguments, $2 is second argument till $n n’th arguments. From 10’th argument, you must need to inclose them in braces like ${10}, ${11} and so on
The name of script itself
Process id of current shell
Values of all the arguments. All agruments are double quoted
Total number of arguments passed to script
Values of all the arguments
Exit status id of last command
Process id of last command

Example Script

Command line arguments can be passed just after script file name with space separated. If any argument have space, put them under single or double quote. Read below simple script.

Now execute this script with 2 arguments and found following results.

$ ./arguments.sh Hello TecAdmin

Was this article helpful to you? Yes 11 No 6