b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

shell脚本for循环 鸟哥的linux私房菜(4)

电脑杂谈  发布时间:2018-01-07 20:06:31  来源:网络整理

那个 $@ 与 $* 基本上还是有所不同!不过,一般使用情况下可以直接记忆 $@ 即可!

范例

[dmtsai@study bin]$ vim how_paras.sh

#!/bin/bash

# Program:

# Program shows the script name, parameters...

# History:

# 2015/07/16 VBird First release

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin

export PATH

echo "The script name is ==> ${0}"

echo "Total parameter number is ==> $#"

[ "$#" -lt 2 ] && echo "The number of parameter is less than 2. Stop here." && exit 0

echo "Your whole parameter is ==> '$@'"

echo "The 1st parameter ==> ${1}"

shell脚本for循环数组_shell脚本for循环_shell脚本for循环100次

echo "The 2nd parameter ==> ${2}"

执行结果如下:

[dmtsai@study bin]$ sh how_paras.sh theone haha quot

The script name is ==> how_paras.sh <==档名

Total parameter number is ==> 3 <==果然有三个参数

Your whole parameter is ==> 'theone haha quot' <==参数的内容全部

The 1st parameter ==> theone <==第一个参数

The 2nd parameter ==> haha <==第二个参数

shift :造成参数变量号码偏移

shift 会移动变量,而且 shift 后面可以接数字,代表拿掉最前面的几个参数的意思。

范例

[dmtsai@study bin]$ vim shift_paras.sh

#!/bin/bash

# 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 ==> '$@'"


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-58905-4.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...