Index Keywords Recent

↶ Return Home

Pass Arguments to a Shell Script

Last Updated May 3rd 2022, 12:41:16 am


The shell command and any arguments to that command appear as numbered shell variables. $0 has the string value of the command itself. Any arguments passed after the script appear as $1, $2, $3 and so on. The count of arguments is in the shell variable $#.[1] [2]


Execute a script from the CLI followed by an argument,

$ ./ <argument1> <argument2> <argument2>

Sample contents of

#!/usr/bin/env bash
example-command $1 $2 $3

In this example $1 would have the value of the first argument given at the command line during script execution.

  1. ↩︎

  2. can be passed to,references to the current script. ↩︎