Shell parameter expansion
2014-07-12 02:23
218 查看
使用sh写一些小型的脚本会使工作更加简单,有部分内容可能大家都比较陌生(至少我是这样),
就是变量有关的参数展开,下面就是一些简单的描述和用法,可以使代码更加简洁
展开运算符
替换运算
${varname:-word} var exist & not null,return value ,else return word
${varname:=word} var exist & not null,return value, else varname=word & return $varname
${varname:?message} var exist & not null,return value, else show message & if not define exit
#test variable is or not exist
${varname:+word} if exist & not null ,return word, else return null
(:)is optional
匹配运算
${variable#pattern}
${variable##pattern}
${variable%pattern}
${variable%%pattern}
# % is from left or right
就是变量有关的参数展开,下面就是一些简单的描述和用法,可以使代码更加简洁
展开运算符
替换运算
${varname:-word} var exist & not null,return value ,else return word
${varname:=word} var exist & not null,return value, else varname=word & return $varname
${varname:?message} var exist & not null,return value, else show message & if not define exit
#test variable is or not exist
${varname:+word} if exist & not null ,return word, else return null
(:)is optional
匹配运算
${variable#pattern}
${variable##pattern}
${variable%pattern}
${variable%%pattern}
# % is from left or right
相关文章推荐
- Shell parameter expansion
- Shell Parameter Expansion之一
- bash's parameter expansion
- linux中shell,awk,sed截取字符串方法总结 Shell 第一种: ${parameter%word} 最小限度从后面截掉word ${parameter%%word} 最大限度从后面
- Set-location:A positional parameter cannot be found that accepts argument 'Shell\Microsoft'.
- shell parameter expansitions
- Linux入门 Part1: 使用控制台(3)-shell,command & parameter(s)
- bash学习之八:shell expansion(shell扩展)
- Configuring SSH Secure Shell for TCP Wrappers Support
- Item 44: Factor parameter-independent code out of templates(Effective C++)
- shell tr
- 一些简单的shell脚本实例
- linux下利用shell脚本实现添加crontab任务
- iOS 自动打包各种渠道的 shell
- shell中的信号处理
- 常用上传shell脚本
- shell脚本连接、读写、操作mysql数据库实例
- shell脚本进行sftp文件批量上传与下载
- shell实现ftp命令示例
- shell中“空格”使用总结