shift:造成参数变量号码偏移
2011-08-30 14:17
211 查看
脚本后面所接的变量是否能够进行偏移 (shift) 呢?什么是偏移啊?我们直接以底下的范例来说明好了, 用范例说明比较好解释!
#!/bin/bash
echo "Total parameter number is ==> $#"
echo "Your whole parameter is ==> '$@'"
echo -e "You'll shift one num,please wait... \n"
shift
echo "Total parameter number is ==> $#"
echo "Your whole parameter is ==> '$@'"
echo -e "You'll shift shift 3 num,please wait... \n"
shift 3
echo "Total parameter number is ==> $#"
echo "Your whole parameter is ==> '$@'"
执行结果:
[oracle@SOR_SYS~]$ sh shift.sh one two three four five six
Total parameter number is ==> 6
Your whole parameter is ==> 'one two three four five six'
You'll shift one num,please wait...
Total parameter number is ==> 5
Your whole parameter is ==> 'two three four five six'
You'll shift shift 3 num,please wait...
Total parameter number is ==> 2
Your whole parameter is ==> 'five six'
光看结果你就可以知道啦,那个 shift 会移动变量,而且 shift 后面可以接数字,代表拿掉最前面的几个参数的意思。 上面的运行结果中,第一次进行 shift 后他的显示情况是『one
two three four five six』,所以就剩下五个啦!第二次直接拿掉三个,就变成『two three four five six 』啦! 这样这个案例可以了解了吗?理解了 shift 的功能了吗?
#!/bin/bash
echo "Total parameter number is ==> $#"
echo "Your whole parameter is ==> '$@'"
echo -e "You'll shift one num,please wait... \n"
shift
echo "Total parameter number is ==> $#"
echo "Your whole parameter is ==> '$@'"
echo -e "You'll shift shift 3 num,please wait... \n"
shift 3
echo "Total parameter number is ==> $#"
echo "Your whole parameter is ==> '$@'"
执行结果:
[oracle@SOR_SYS~]$ sh shift.sh one two three four five six
Total parameter number is ==> 6
Your whole parameter is ==> 'one two three four five six'
You'll shift one num,please wait...
Total parameter number is ==> 5
Your whole parameter is ==> 'two three four five six'
You'll shift shift 3 num,please wait...
Total parameter number is ==> 2
Your whole parameter is ==> 'five six'
光看结果你就可以知道啦,那个 shift 会移动变量,而且 shift 后面可以接数字,代表拿掉最前面的几个参数的意思。 上面的运行结果中,第一次进行 shift 后他的显示情况是『one
two three four five six』,所以就剩下五个啦!第二次直接拿掉三个,就变成『two three four five six 』啦! 这样这个案例可以了解了吗?理解了 shift 的功能了吗?
相关文章推荐
- 内存分区导出的环境变量参数丢失,造成镜像打包出错
- 一天一篇批处理之——Part5: 跟变量/参数有关的高频命令set,shift,for
- 如何使用变量给数据源控件参数赋值、如何动态增减数据源控件参数并支持分页
- Linux内核参数配置文件修改(/proc/sys与/etc/sysctl.conf变量对应关系)
- ASP.NET Core中使用GraphQL - 第五章 字段, 参数, 变量
- bash变量-位置参数与预定义变量
- asp.net变量.Substring(参数1,参数2)
- Varnish解决带参数的URL可能造成多份缓存的问题
- 参数化之利用CSV Data Set Config从文件读取参数并关联变量
- SQL*plus set 环境变量参数详解
- xcode4的环境变量,Build Settings参数,workspace及联编设置
- Shell 统计导出数据 awk 里使用shell变量 参数
- C程序的参数和环境变量
- QString::arg()//用字符串变量参数依次替代字符串中最小数值
- UTF-8的项目向GBK项目传递的参数中携带了中文造成中文乱码的解决方案。
- 怎样在不使用第三方变量交换函数的两个参数
- Java中如何获得集合变量的集合中的类型参数
- JavaScript函数参数以及变量声明讨论
- Nginx内置变量以及日志格式变量参数详解
- [MySQL] 变量(参数)的查看和设置 [转]