Linux Shell location Variables in detail what are positional variables?
Simply put, when the user runs the script, input parameters, the variables corresponding to these parameters are called positional variables.
Example:
[[email protected] scripts]# ./ping.sh www.baidu.comHost www.baidu.com is up.[[email protected] scripts]# ./ping.sh klsdjfkldjfkldf.kljjfdkljfdljds.comHost klsdjfkldjfkldf.kljjfdkljfdljds.com is down.
Assign a value when invoking a script.
To view the script:
Position parameters
$: The first parameter, such as./ping.sh 1.1.1.1 2.2.2.2, then $1.1.1.1
$: The second parameter, such as./ping.sh 1.1.1.1 2.2.2.2, then the $2.2.2.2
......
$: script Name
$#: A total of several parameters
[Email protected]: Show all parameters
Example:
查看脚本#!/bin/bash -#arppinging or XiaoPengecho ‘ $0 $1 $2 $# [email protected]‘echo $0 $1 $2 $# [email protected]**执行脚本**[[email protected] scripts]# ./var.sh 1 2 3 4 5 $0 $1$2$# [email protected]./var.sh 1 2 5 1 2 3 4 5
Summary: Remember a few common parameters $0\$1\$#\[email protected] can.
Copyright: arppinging
"Shell" Linux shell location variables detailed