How to get the n
th positional argument in Bash, where n
is variable?
相关问题
- JQ: Select when attribute value exists in a bash a
- Is it possible to pass command-line arguments to @
- bash print whole line after splitting line with if
- “command not found” errors in expect script execut
- grep using grep results
相关文章
- Check if directory exists on remote machine with s
- How can I convert a PHP function's parameter l
- Reverse four length of letters with sed in unix
- Launch interactive SSH bash session from PHP
- BASH: Basic if then and variable assignment
- Bash script that creates a directory structure
- Test if File/Dir exists over SSH/Sudo in Python/Ba
- How can I create a “tmp” directory with Elastic Be
As you can see in the Bash by Example, you just need to use the automatic variables $1, $2, and so on.
$# is used to get the number of arguments.
Use Bash's indirection feature:
Running that file:
Produces:
Edit:
You can also do array slicing:
but not array subscripts:
$0
contains the name of the script.Read
Handling positional parameters
and
Parameter expansion
$0: the first positional parameter
$1 ... $9: the argument list elements from 1 to 9
If
N
is saved in a variable, useif it's a constant use
since
does not mean the same!