Chinaunix
标题:
一段bash 中的一句 不知含义
[打印本页]
作者:
wuxiaobo_2009
时间:
2013-12-25 14:39
标题:
一段bash 中的一句 不知含义
1 #!/bin/bash
2 # 还是行星.
3
4 # 分配行星的名字和它距太阳的距离.
5
6 for planet in "Mercury 36" "Venus 67" "Earth 93" "Mars 142" "Jupiter 483"
7 do
8 set -- $planet
# 解析变量"planet"并且设置位置参数.
9 # "--" 将防止$planet为空,或者是以一个破折号开头.
不理解
10
11 # 可能需要保存原始的位置参数,因为它们被覆盖了.
12 # 一种方法就是使用数组,
13 # original_params=("$@")
14
15 echo "$1 $2,000,000 miles from the sun"
16 #-------two tabs---把后边的0和$2连接起来
17 done
18
19 # (Thanks, S.C., for additional clarification.)
20
21 exit 0
作者:
jason680
时间:
2013-12-25 14:49
回复
1#
wuxiaobo_2009
$ set a -2; echo $1,$2
a,-2
$ set -a -2; echo $1,$2
bash: set: -2: invalid option
set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
a,-2
$ set
--
-a -2; echo $1,$2
-a,-2
作者:
dn833
时间:
2013-12-25 15:30
参考man bash
-- A -- signals the end of options and disables further option processing. Any arguments after the -- are treated as filenames and argu-
ments. An argument of - is equivalent to --.
复制代码
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2