您的位置:首页 > 运维架构 > Shell

Bash Shell中Shift用法

2012-10-12 13:49 162 查看
转自:http://www.chengyongxu.com/blog/bash-shell%E4%B8%ADshift%E7%94%A8%E6%B3%95/

shift可以用来向左移动位置参数。

Shell的名字 $0

第一个参数 $1

第二个参数 $2

第n个参数 $n

所有参数 $@ 或 $*

参数个数 $#

shift默认是shift 1

以下边为例:

view
source

print?

01
cat
shift
.sh
02
#----------------------------输出文字-开始----------------------------
03
#!/bin/bash
04
until
[
 -z
"$1"
]
#
 Until all parameters used up
05
do
06
echo
"$@
 "
07
shift
08
done
09
#----------------------------输出文字-结束----------------------------
10
11
sh
shift
.sh
 1 2 3 4 5 6 7 8 9
12
#----------------------------输出文字-开始----------------------------
13
1
 2 3 4 5 6 7 8 9
14
2
 3 4 5 6 7 8 9
15
3
 4 5 6 7 8 9
16
4
 5 6 7 8 9
17
5
 6 7 8 9
18
6
 7 8 9
19
7
 8 9
20
8
 9
21
9
22
#----------------------------输出文字-结束----------------------------
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: