Linux Shell参数扩展(Parameter Expansion)
来源:互联网 发布:华硕驱动升级软件 编辑:程序博客网 时间:2024/05/17 01:21
本文主要参考:http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02
其他资料:http://www.ibm.com/developerworks/cn/linux/l-bash-parameters.html
参数扩展的表示形式为:${expression}。expression包括各种字符直到匹配上'}'。当出现以下情况时候'}'不会被检查来匹配:
1)在转义字符\之后,如\{;
2)在引号里面,如‘}’;
3) 在算术表达式,命令替换或者变量扩展里面的,如${value}
最简单的参数扩展形式如:${parameter}
使用如下模式可以修改参数扩展:
[hdfs@cdh51kdc ~]$ bb=3[hdfs@cdh51kdc ~]$ echo ${aa}[hdfs@cdh51kdc ~]$ echo ${bb}3[hdfs@cdh51kdc ~]$ echo ${aa-${bb}}3[hdfs@cdh51kdc ~]$ aa=2[hdfs@cdh51kdc ~]$ echo ${aa-${bb}}2
[hdfs@cdh51kdc ~]$ echo ${aa-${bb}}2[hdfs@cdh51kdc ~]$ echo ${aa:=${bb}}2[hdfs@cdh51kdc ~]$ echo ${cc}[hdfs@cdh51kdc ~]$ echo ${cc:=${bb}}3[hdfs@cdh51kdc ~]$ echo ${cc}3
[hdfs@cdh51kdc ~]$ echo ${cc:?"Value not set"}3[hdfs@cdh51kdc ~]$ echo ${dd:?"Value not set"}-bash: dd: Value not set
[hdfs@cdh51kdc ~]$ echo ${cc:+"Value not set"}Value not set[hdfs@cdh51kdc ~]$ echo ${dd:+"Value not set"}
${#parameter}
[hdfs@cdh51kdc ~]$ echo ${#cc}1[hdfs@cdh51kdc ~]$ echo ${#dd}0
The following four varieties of parameter expansion provide for substring processing. In each case, pattern matching notation (see Pattern Matching Notation), rather than regular expression notation, shall be used to evaluate the patterns. If parameter is '#', '*', or '@', the result of the expansion is unspecified. If parameter is unset and set -u is in effect, the expansion shall fail. Enclosing the full parameter expansion string in double-quotes shall not cause the following four varieties of pattern characters to be quoted, whereas quoting characters within the braces shall have this effect. In each variety, if word is omitted, the empty pattern shall be used.
${parameter%[word]}
[hdfs@cdh51kdc ~]$ echo ${cc}Value not set[hdfs@cdh51kdc ~]$ echo ${cc%"et"}Value not s
[hdfs@cdh51kdc ~]$ echo ${cc%%t*}Value no[hdfs@cdh51kdc ~]$ echo ${cc%t*}Value not se
[hdfs@cdh51kdc ~]$ echo ${cc#*t}set[hdfs@cdh51kdc ~]$ echo ${cc##*t}[hdfs@cdh51kdc ~]$ echo ${cc#V}alue not set
- Linux Shell参数扩展(Parameter Expansion)
- Shell Parameter Expansion之一
- Shell parameter expansion
- 参数展开(parameter expansion)
- bash之参数和变量扩展(parameter and variable expansion)
- Parameter expansion
- Variable expansion Modifiers (parameter expansion)
- Bash编程七大展开之参数展开(Parameter Expansion)ZT
- Bash编程七大展开之参数展开(Parameter Expansion)
- Bash编程七大展开之参数展开(Parameter Expansion)
- bash学习之八:shell expansion(shell扩展)
- bash之算术扩展(arithmetic expansion)
- shell参数扩展
- shell参数扩展
- shell参数扩展
- shell参数扩展
- shell参数扩展${}
- Linux Shell 编程 之 参数和变量扩展
- ROC和AUC介绍以及如何计算AUC
- 判断桌面快捷方式是否已经创建
- VC++常用技巧
- FTP的主动模式和被动模式
- Ubuntu安装swftools
- Linux Shell参数扩展(Parameter Expansion)
- js页面刷新跳转的几种方式及区别
- iOS8指纹验证TouchID
- struts2文件下载的时候,处理中文文件名的问题
- gmake和make 的区别
- 一组SQL面试题
- struts整合spring的3中方法,怕忘记转一下
- Unity之游戏对象隐藏的问题
- Hadoop Hive sql语法详解