LOCAL_TEST="test" //给本地变量 LOCAL_TEST 赋值 test
echo $LOCAL_TEST //也可以 echo ${LOCAL_TEST}
set | grep LOCAL_TEST //用 set 命令查看本地变量(再重启终端后本地变量消失)
readonly LOCALTEST
export MYTEST="are you ok"
beyes@linux-beyes:~> echo $MYTEST
are you ok
unset MYTEST
${Variable name} | 显示实际值到 variable name |
${Variable name:+value} | 如果设置了 variable name,则显示其值为 value,否则为空 |
${Variable name:?value} | 如果未设置 varialbe name,则显示用户定义的错误信息 value |
${Variable name:-value} | 如果未设置 varialbe name,则显示其指 value |
${Varialble name:=value} | 如果未设置 variable name,则设置其值为 value,并显示 |
$0 | $1 | $2 | $3 | $4 | $5 | $6 | $7 | $8 | $9 |
脚本名字 | A | B | C | D | E | F | G | H |
#!/bin/bash
#parm
echo "This is script name : $0"
echo "This is script 1 parameter: $1"
echo "This is script 2 parameter: $2"
echo "This is script 3 parameter: $3"
echo "This is script 4 parameter: $4"
echo "This is script 5 parameter: $5"
echo "This is script 6 parameter: $6"
echo "This is script 7 parameter: $7"
echo "This is script 8 parameter: $8"
echo "This is script 9 parameter: $9"
This is script name : ./parm.sh
This is script 1 parameter:
This is script 2 parameter:
This is script 3 parameter:
This is script 4 parameter:
This is script 5 parameter:
This is script 6 parameter:
This is script 7 parameter:
This is script 8 parameter:
This is script 9 parameter:
./parm.sh A B C D EEFF
This is script name : ./parm.sh
This is script 1 parameter: A
This is script 2 parameter: B
This is script 3 parameter: C
This is script 4 parameter: D
This is script 5 parameter: EEFF
This is script 6 parameter:
This is script 7 parameter:
This is script 8 parameter:
This is script 9 parameter:
#!/bin/bash #parm-1 ls -lh /home/beyes/$1 |
beyes@linux-beyes:~/shell_sript> sh parm-1.sh TomatoWinXP_SP3_V1.21.iso
-rw-r--r-- 1 beyes users 687M 12-08 18:18 /home/beyes/TomatoWinXP_SP3_V1.21.iso
beyes@linux-beyes:~/桌面> echo $PS1
$(ppwd \\l)\\u@\\h:\\w>
beyes@linux-beyes:~/桌面> echo $PS2
>
beyes@linux-beyes:~> echo $MANPATH
/usr/lib/mpi/gcc/openmpi/share/man:/usr/local/man:/usr/local/share/man:/usr/share/man
#!/bin/bash #parm echo "这是脚本的名称: $0" echo "这是脚本的第1个位置参数:$1" echo "这是脚本的第2个位置参数:$2" echo "这是脚本的第3个位置参数:$3" echo "这是脚本的第4个位置参数:$4" echo "这是脚本的第5个位置参数:$5" echo "这是脚本的第6个位置参数:$6" echo "这是脚本的第7个位置参数:$7" echo "这是脚本的第8个位置参数:$8" echo "这是脚本的第9个位置参数:$9" echo "显示参数的个数:$#" echo "显示脚本全部参数:$*" echo "显示进程ID:$$" echo "显示前一命令运行后状态:$?" |
beyes@linux-beyes:~/shell_sript> ./parm-2.sh A beyes home
这是脚本的名称: ./parm-2.sh
这是脚本的第1个位置参数:A
这是脚本的第2个位置参数:beyes
这是脚本的第3个位置参数:home
这是脚本的第4个位置参数:
这是脚本的第5个位置参数:
这是脚本的第6个位置参数:
这是脚本的第7个位置参数:
这是脚本的第8个位置参数:
这是脚本的第9个位置参数:
显示参数的个数:3
显示脚本全部参数:A beyes home
显示进程ID:6342
显示前一命令运行后状态:0
#!/bin/bash #parm echo "这是脚本的名称: $0" echo "这是脚本的第1个位置参数:$1" echo "这是脚本的第2个位置参数:$2" echo "这是脚本的第3个位置参数:$3" echo "这是脚本的第4个位置参数:$4" echo "这是脚本的第5个位置参数:$5" echo "这是脚本的第6个位置参数:$6" echo "这是脚本的第7个位置参数:$7" echo "这是脚本的第8个位置参数:$8" echo "这是脚本的第9个位置参数:$9" echo "显示参数的个数:$#" echo "显示脚本全部参数:'$@'" echo "显示进程ID:$$" echo "显示前一命令运行后状态:$?" shift echo "这是脚本的第1个位置参数:$1" echo "这是脚本的第2个位置参数:$2" |
./parm-2.sh one two three four
beyes@linux-beyes:~/shell_sript> ./parm-2.sh one two three four
这是脚本的名称: ./parm-2.sh
这是脚本的第1个位置参数:one
这是脚本的第2个位置参数:two
这是脚本的第3个位置参数:three
这是脚本的第4个位置参数:four
这是脚本的第5个位置参数:
这是脚本的第6个位置参数:
这是脚本的第7个位置参数:
这是脚本的第8个位置参数:
这是脚本的第9个位置参数:
显示参数的个数:4
显示脚本全部参数:'one two three four'
显示进程ID:6676
显示前一命令运行后状态:0
这是脚本的第1个位置参数:two
这是脚本的第2个位置参数:three //被移位了!
com-change.sh hello.sh parm-1.sh parm-2.sh parm.sh
com-change.sh hello.sh parm-1.sh parm-2.sh parm.sh
*
echo -e "ert, $SHELL '\\n* home `echo beyes`"
ert, /bin/bash '
* home beyes
& * + ^ $ ` " | ?
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |