# Program:
#
Program shows the effect of shift function.
# History:
# 2009/02/17
VBird
First release
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
echo "Total parameter number is ==> $#"
echo "Your whole parameter is ==> '$@'"
shift
#
½
行第一次『一
个变
量的
shift
』
echo "Total parameter number is ==>
$#"
echo "Your whole parameter is ==> '$@'"
shift 3
#
½
行第二次『三
个变
量的
shift
』
echo "Total parameter number is ==> $#"
echo "Your whole parameter is ==> '$@'"
这玩意的执行成果如下:
[dmtsai@study bin]$
sh shift_paras.sh one two three four five six
<==
给
予六
个参数
Total parameter number is ==> 6
<==
最原始的
参数变
量情
况
Your whole parameter is ==> 'one two three four five six'
Total parameter number is ==> 5
<==
第一次偏移,看底下
发现
第一
个
one
不
见
了
Your whole parameter is ==> 'two three four five six'
Total parameter number is ==> 2
<==
第二次偏移掉三
个
,
two three four
不
见
了
Your whole parameter is ==> 'five six'
光看½果你就可以知道啦,那个
shift
会移动变量,而且
shift
后面可以½数字,代表拿掉最前面的
几个参数的意思。
上面的执行½果中,第一次½行
shift
后他的显示情况是『
one two three four five
six
』,所以就剩下五个啦!第二次直½拿掉三个,就变成『
two three four five six
』啦!
这样这个
案例可以了½了吗?理½了
shift
的功能了吗?
上面这几个例子都很简单吧?几乎都是利用
bash
的相关功能而已~
不难啦~底下我们就要使用条
件判断式来½行一些分别功能的设定了,好好瞧一瞧先~
12.4
条件判断式
只要½到『程序』的话,那么条件判断式,亦即是『
if then
』这种判别式肯定一定要学习的!
因为
很多时候,我们都必须要依据某些数据来判断程序该如何½行。举例来说,我们在上头的
ans_yn.sh
讨
论输入响应的范例中不是有练习当使用者输入
Y/N
时,必须要执行不同的讯息输出吗?简单的方式
可以利用
&&
与
||
,但如果我还想要执行一堆指令呢?那真的得要
if then
来帮忙啰~底下我们就
来聊一聊!