免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
论坛 操作系统 Solaris set
最近访问板块 发新帖
查看: 2453 | 回复: 4
打印 上一主题 下一主题

set [复制链接]

论坛徽章:
1
IT运维版块每日发帖之星
日期:2015-09-01 06:20:00
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-08-05 18:36 |只看该作者 |倒序浏览
set --  特性怎么用?

论坛徽章:
1
IT运维版块每日发帖之星
日期:2015-09-01 06:20:00
2 [报告]
发表于 2011-08-05 18:57 |只看该作者
就是 控制  $1 $2 $3  你可以在任意位置用这个命令更改 位置参数

论坛徽章:
1
辰龙
日期:2013-09-23 11:57:00
3 [报告]
发表于 2011-10-11 16:20 |只看该作者
回答你:
a 脚本如下:
#!/bin/bash
echo $*
set -- o o p p i i
echo $*

调用:./a a b c
输入结果:
a b c
o o p p i i


把当前传入的参数改成-- 后面的参数。

论坛徽章:
1
IT运维版块每日发帖之星
日期:2015-09-01 06:20:00
4 [报告]
发表于 2011-10-17 20:22 |只看该作者
set -- a b c d
count=$#
在函数内设置参数

论坛徽章:
0
5 [报告]
发表于 2011-10-18 03:49 |只看该作者
set in shell script overrides to default value of position variables $1, $2, $3 ...

If you don't have set command in your shell script, $1 automatically takes the vaule of the first parameter you pasted to the shell script. $2 takes the second parameter and so on.

For example:

Your first script is script1.sh

  1. #!/bin/sh
  2. echo $1
  3. echo $2
复制代码
When you run it as:  script1.sh start all , the shell will automatically assign $1=start and $2=all. The output of running this script is:
start
all

Your second script is script2.sh

  1. #!/bin/sh
  2. set `who -r`
  3. echo $1
  4. echo $2
复制代码
When you run it as:  script2.sh start all , the output will be:
.
run-level

This is because the output of who -r command is something like:
.       run-level 3  Aug 13 11:40     3      0  S

So now $1=. , $2=run-level, $3=3, $4=Aug, $5=13 ... and $1 is no longer start and $2 is no longer all any more.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP