QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2500|回复: 6

shell中shift的作用

[复制链接]
发表于 2005-5-12 14:33:42 | 显示全部楼层 |阅读模式
请问在SHELL编程中SHIFT的作用是什么啊?
发表于 2005-5-12 18:09:36 | 显示全部楼层
移除最左边的一个参数
回复

使用道具 举报

发表于 2005-5-12 18:14:27 | 显示全部楼层
[code:1]
#!/usr/local/bin/bash

echo $@
shift
echo $@
[/code:1]
$@ 表示所有的位置参数。
测试:
[code:1]
bash-2.05b# ./shift.sh 1 2 3 4
1 2 3 4
2 3 4
bash-2.05b#
[/code:1]
回复

使用道具 举报

发表于 2005-5-12 19:07:26 | 显示全部楼层
也可左移n个参数
/home/lee#set a b c d e f g
/home/lee#shift 2;echo $*;shift 3;echo $*
c d e f g
f g
回复

使用道具 举报

发表于 2005-5-12 20:18:20 | 显示全部楼层
[quote:14926e73d5="kornlee"]也可左移n个参数
/home/lee#set a b c d e f g
/home/lee#shift 2;echo $*;shift 3;echo $*
c d e f g
f g[/quote]
长见识了,多谢kornlee大哥
回复

使用道具 举报

发表于 2005-5-13 12:16:09 | 显示全部楼层
[quote:a6a93d13af="MichaelBibby"][quote:a6a93d13af="kornlee"]也可左移n个参数
/home/lee#set a b c d e f g
/home/lee#shift 2;echo $*;shift 3;echo $*
c d e f g
f g[/quote]
长见识了,多谢kornlee大哥 [/quote]
汗 #_!
回复

使用道具 举报

发表于 2005-5-17 10:33:04 | 显示全部楼层
顶了! :-)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-7-8 13:36 , Processed in 0.056332 second(s), 16 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表