Difference between revisions of "$1"

From Linux Shell Scripting Tutorial - A Beginner's handbook
Jump to navigation Jump to search
Line 6: Line 6:
 
* ${10} is the tenth argument and must be enclosed in brackets after $9.
 
* ${10} is the tenth argument and must be enclosed in brackets after $9.
 
* ${11} is the eleventh argument.
 
* ${11} is the eleventh argument.
 +
==$1 and positional parameters example==
 
==$1 in bash functions==
 
==$1 in bash functions==
 
In bash functions, $1 server as the first function parameter and so on.
 
In bash functions, $1 server as the first function parameter and so on.
 +
===Example===

Revision as of 06:19, 30 January 2020

$1 is the first command-line argument passed to the shell script. Also, know as Positional parameters. For example, $0, $1, $3, $4 and so on. If you run ./script.sh filename1 dir1, then:

  • $0 is the name of the script itself (script.sh)
  • $1 is the first argument (filename1)
  • $2 is the second argument (dir1)
  • $9 is the ninth argument
  • ${10} is the tenth argument and must be enclosed in brackets after $9.
  • ${11} is the eleventh argument.

$1 and positional parameters example

$1 in bash functions

In bash functions, $1 server as the first function parameter and so on.

Example