Quick Answer: How Do You Pass a Command Line Argument in Linux Shell Script?
Contents

To pass a command line argument we can simply write them after script name separated with space. All command line parameters can be access by their position number using $. A sample example of passing command line argument to shell script.

How do you pass command line arguments in shell script?

Arguments can be passed to the script when it is executed, by writing them as a space-delimited list following the script file name. Inside the script, the $1 variable references the first argument in the command line, $2 the second argument and so forth. The variable $0 references to the current script.

How do I run a command line argument in bash?

Command Line Arguments in Shell Script

  1. Special Variable. Variable Details.
  2. $1 to $n. $1 is the first arguments, $2 is second argument till $n n’th arguments. …
  3. $0. The name of script itself.
  4. $$ Process id of current shell.
  5. $* Values of all the arguments. …
  6. $# Total number of arguments passed to script.
  7. [email protected] …
  8. $?

21 июн. 2020 г.

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest