理解Bash shell中shift命令
来源:互联网 发布:国家电网软件开发 编辑:程序博客网 时间:2024/06/06 07:52
1. man下的解释:
[root@desktop31 log]# man shift
...
The positional parameters from n+1 ... are renamed to $1 ....
Parameters represented by the numbers $# down to $#-n+1 are
unset. n must be a non-negative number less than or equal to
$#. If n is 0, no parameters are changed. If n is not given,
it is assumed to be 1. If n is greater than $#, the positional
parameters are not changed. The return status is greater than
zero if n is greater than $# or less than zero; otherwise 0.
...
shift n表示把第n+1个参数移到第1个参数, 即命令结束后$1的值等于$n+1的值, 而命令执行前的前面n个参数不能被再次引用, 后面$#-n+1到$#的参数被unset, 参数的个数减少为$#-n个.
n的值不能为负数, 若n为0或大于参数个数$#则参数不变, 若n没有给定则默认为1. 当n小于0或者大于参数个数$#时shift命令的返回值大于0, 否则返回0.
2. 小例子
[root@desktop31 log]# vim test
#!/bin/bash
echo '>> before shift '
echo 'para count is ' $#
echo '$1 2 3 is ' $1, $2, $3.
shift 2
echo '>> after shift 2'
echo 'para count is ' $#
echo '$1 2 3 is ' $1, $2, $3.
[root@desktop31 log]# ./test a b c
>> before shift
para count is 3
$1 2 3 is a, b, c.
>> after shift 2
para count is 1
$1 2 3 is c, , .
[root@desktop31 log]#
- 理解Bash shell中shift命令
- Bash Shell中Shift用法
- Bash Shell中Shift用法分享
- shell 内置命令shift
- shell中的shift命令
- linux shell命令shift
- 【Bash百宝箱】shell内建命令之pwd、readonly、return、shift
- shell 中 shift 位移
- Unix Shell中使用Shift命令操作脚本参数
- linux shell脚本中shift命令的使用
- shell中“source”、“.”和“bash”命令
- Docker中进入bash shell命令
- Linux Shell中的shift命令
- bash shell 命令消除
- Bash shell 命令 备忘
- bash shell常见命令
- bash shell命令
- Bash Shell let命令
- vs2008 c# 对sql插入操作
- webwork总结
- 理解javascript函数调用和“this”
- Spring
- web开发资料收集
- 理解Bash shell中shift命令
- C#调用c++的标准动态链接库dll
- 使用VS2010 C#编写ActiveX控件
- c#调用c++写成的dll文件
- java synchronized详解
- android应用开发笔记---常用控件RadioGroup和RadioButton及Toast
- 删除control list 记录
- 【白话系列】倍增算法
- 二元树中和为某一值的所有路径[数据结构]