test.sh parameter
in test.sh, how can I get the parameter?
test.sh
If this is a single parameter, you use $1( $2and so on, $0is the name of the script). Then, to get ALL parameters, you use$@
$1
$2
$0
$@
Access $0through $9( $0is the name of the script). Alternatively, $*returns a list of all parameters.
$9
$*
If you want to access parameters one by one or want to access parameters beyond the 9th, you can shiftparameters:
shift
echo $1 shift echo $1
When called like this:
./script.sh foo bar
will produce:
foo bar
$NUM, NUM - , . $0 - , script. $# .
test.sh alpha beta gamma echo $0 echo $1 echo $2 echo $3 echo $#
test.sh alpha beta gamma 3
echo "$ @";
You can also use shiftto "shift" the parameters. $1contains the first parameter. If you call shift, then the second parameter will be "shifted" by $1, etc.
At least in Bash, you can make any of them to access any parameter, including 10 or more:
echo "${10}" echo "${@:10:1}"
To iterate over all parameters:
for arg do echo "$arg" done
This form implies for arg in "$@"
for arg in "$@"
Source: https://habr.com/ru/post/1751577/More articles:Is Azure Shared Access Signature suitable, can anyone access my blobs? - .netRead / write Nibbles (without bit fields) in C / C ++ - c ++What is the best denormalization practice in CQRS? - phpКогда использовать InterfaceBuilder для создания представлений? - objective-cjQuery простой запрос ajax не работает - javascriptC90 - C99: register structure - cWPF ComboBox и SelectedItem привязка к XML DataSource - wpfWhat do line numbers in perl -cw mean? - perlDoes spring commit when it shouldn't be? (related to Oracle autocommit) - javaPostgreSQL: exists against left join - performanceAll Articles