请教两个shell指令set与getopt

素衣白马客京华 2014-06-09 10:30:02
set -- `/usr/bin/getopt f:d: $*`

这条指令是什么意思?
...全文
611 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
引用 3 楼 ljc007 的回复:
[quote=引用 2 楼 judwenwen2009 的回复:] 非常感谢,你举的set的例子我试过了,果然是这样,但为什么-f会设置到$1里了呢,而不是$0、$2、$3?
[root]# set -- -a -b -c [root]# echo $1 -a [root]# echo $2 -b [root]# echo $3 -c 这样能理解吗?[/quote] 谢谢,我试过是这样的,就是难以理解set命令是设置环境变量的,为何会默认写入$1呢
ljc007 2014-06-10
  • 打赏
  • 举报
回复
引用 2 楼 judwenwen2009 的回复:
非常感谢,你举的set的例子我试过了,果然是这样,但为什么-f会设置到$1里了呢,而不是$0、$2、$3?
[root]# set -- -a -b -c [root]# echo $1 -a [root]# echo $2 -b [root]# echo $3 -c 这样能理解吗?
  • 打赏
  • 举报
回复
引用 1 楼 ljc007 的回复:
getopt 的作用是获取参数,参考: http://www.tldp.org/LDP/abs/html/string-manipulation.html#GETOPTSIMPLE http://www.tldp.org/LDP/abs/html/extmisc.html#GETOPTY http://www.tldp.org/LDP/abs/html/internal.html#GETOPTSX set 的作用是设置位置参数 -- 的作用是把元字符 * ? 等作为普通字符 试验: set -f echo $1 set -- -f echo $1
非常感谢,你举的set的例子我试过了,果然是这样,但为什么-f会设置到$1里了呢,而不是$0、$2、$3?
ljc007 2014-06-09
  • 打赏
  • 举报
回复
getopt 的作用是获取参数,参考: http://www.tldp.org/LDP/abs/html/string-manipulation.html#GETOPTSIMPLE http://www.tldp.org/LDP/abs/html/extmisc.html#GETOPTY http://www.tldp.org/LDP/abs/html/internal.html#GETOPTSX set 的作用是设置位置参数 -- 的作用是把元字符 * ? 等作为普通字符 试验: set -f echo $1 set -- -f echo $1

1,543

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 Solaris
社区管理员
  • Solaris
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧