Note: Command line arguments are also known as positional parameters.
Multiple shifts in a single attempt may be performed by furnishing the desired number of shifts to the shift command as an argument. New first argument after second shift: MacOS New first argument after first shift: Linux The first command line argument is: Windows The arguments supplied are : Windows Linux MacOS HPUX There are 4 arguments pass at command line Let’s re-run the script with following command line arguments, $ cat arguments.shĮcho "New first argument after first shift: $1"Įcho "New first argument after second shift: $1" The above script would look like below after adding shift command to it. During this move, the first argument is lost. The shift command is used to move command line arguments one position to the left. ‘ ’ is always preferred over ‘$*’, to understand their difference, let’s create following script, $ vi arguments-new.shĮxecute the script and notice the difference The key difference between these two variables is that ‘$*’ represent all the parameters in single string whereas ‘ ’ represent arguments as a array or expands to multiple arguments. In above script, we can also use ‘ ’ in place of $* to get all the arguments. arguments.sh Debian RockyLinux Ubuntu RHEL SUSE Now execute the script with following command line arguments $. #This Script demonstrate the usage of command line arguments in bash scriptĮcho "There are $# arguments pass at command line"Įcho "The first command line argument is: $1"Īssign Executable permissions to the script using chmod command Let’s create a shell script with name “arguments.sh”, it will show the command line arguments that were supplied and count number of arguments, value of first argument and Process ID (PID) of the Script.