jerry_cym 发表于 2005-5-12 14:33:42

shell中shift的作用

请问在SHELL编程中SHIFT的作用是什么啊?

MichaelBibby 发表于 2005-5-12 18:09:36

移除最左边的一个参数

MichaelBibby 发表于 2005-5-12 18:14:27


#!/usr/local/bin/bash

echo $@
shift
echo $@

$@ 表示所有的位置参数。
测试:

bash-2.05b# ./shift.sh 1 2 3 4
1 2 3 4
2 3 4
bash-2.05b#

kornlee 发表于 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

MichaelBibby 发表于 2005-5-12 20:18:20

也可左移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
长见识了,多谢kornlee大哥 :)

kornlee 发表于 2005-5-13 12:16:09

也可左移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
长见识了,多谢kornlee大哥 :)
汗 #_!

luronghui 发表于 2005-5-17 10:33:04

顶了! :-)
页: [1]
查看完整版本: shell中shift的作用