bash's parameter expansion
[bash's parameter expansion]
#: find first from left, remove-left
##: find last from left, remove left
%: find first from right, remove right
%%: find last from right, remove right
example 1:
parameter result
----------- ------------------------------
${NAME} polish.ostrich.racing.champion
${NAME#*.} ostrich.racing.champion
${NAME##*.} champion
${NAME%%.*} polish
${NAME%.*} polish.ostrich.racing
example 2:
parameter result
----------- --------------------------------------------------------
${FILE} /usr/share/java-1.4.-sun/demo/applets/Clock/Clock.class
${FILE#*/} usr/share/java-1.4.-sun/demo/applets/Clock/Clock.class
${FILE##*/} Clock.class
${FILE%%/*}
${FILE%/*} /usr/share/java-1.4.2-sun/demo/applets/Clock
string slice:
${string::} # The third character of string (, , = third)
${string:} # The string starting from the second character
# Note: this is equivalent to ${string#?}
${string%?} # The string with its last character removed.
${string: -} # The last character of string
${string:(-)} # The last character of string, alternate syntax
# Note: string:- means something entirely different; see below. ${file%.mp3} # The filename without the .mp3 extension
# Very useful in loops of the form: for file in *.mp3; do ...
${file%.*} # The filename without its last extension
${file%%.*} # The filename without all of its extensions
${file##*.} # The extension only, assuming there is one. If not, will expand to ${file}
toupper (^) and tolower (,):
# string='hello, World!'
parameter result
----------- --------------------------------------------------------
${string^} Hello, World! # First character to uppercase
${string^^} HELLO, WORLD! # All characters to uppercase
${string,} hello, World! # First character to lowercase
${string,,} hello, world! # All characters to lowercase
assignment:
${var-word} # if var is defined, use var; otherwise, "word"
${var+word} # if var is defined, use "word"; otherwise, nothing
${var=word} # if var is defined, use var; otherwise, use "word" AND...
# also assign "word" to var
${var?error} # if var is defined, use var; otherwise print "error" and exit
参考: http://bash.cumulonim.biz/BashFAQ(2f)073.html
bash's parameter expansion的更多相关文章
- bash shell parameter expansion
1 ${parameter%word}和${parameter%%word} ${parameter%word},word是一个模式,从parameter这个参数的末尾往前开始匹配.单个%进行最短匹配 ...
- Linux Shell參数扩展(Parameter Expansion)
本文主要參考:http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02 其它资料:ht ...
- 【转】bash 参数展开(Parameter Expansion)
转自:http://www.360doc.com/content/13/0513/20/9437165_285204629.shtml ${parameter} 取parameter的值 ${para ...
- Linux Shell参数扩展(Parameter Expansion)
Shell Command Language在线文档: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html ...
- [2012-04-25]shell大括号参数扩展(Parameter Expansion)
参考了shell十三问 以及http://hi.baidu.com/leejun_2005/blog/item/ebfee11a4177ddc1ac6e751d.html 提炼下记忆方式: {% ca ...
- Shell parameter expansion
使用sh写一些小型的脚本会使工作更加简单.有部分内容可能大家都比較陌生(至少我是这样). 就是变量有关的參数展开,以下就是一些简单的描写叙述和使用方法.能够使代码更加简洁 展开运算符 替换运算 ${v ...
- 再谈 $* 和 $@ 在 Bash 中的表现
除非特别说明,本文中出现的 Shell 均指 Bash 4.3.首先说一个基础知识:Shell 中的变量在展开成值(Parameter Expansion)之后,这个值在某些上下文(Context)中 ...
- (转载)Bash 中的特殊字符大全
转自:https://linux.cn/article-5657-1.html Linux下无论如何都是要用到shell命令的,在Shell的实际使用中,有编程经验的很容易上手,但稍微有难度的是she ...
- 学习bash
工作8年,前6年基本是Windows环境下,也就是个鼠标党:两年前换工作开始用linux,也就开始了领略了命令行的强大,无论是直接在命令行组合命令,也还写几行简单的shell脚本,其能完成的功能往往令 ...
随机推荐
- 洛谷 P2828 Switching on the Lights(开关灯)
传送门 题目大意:n*n的网格,每个网格是一个房间 都关着灯,只有(1,1)开着灯,且(x,y)有着(z,k)房间灯的开关. 问从(1,1)开始走最多点开几盏灯. 题解:搜索+骗分. 劳资的骗分天下无 ...
- DZ X3 和 ECshop 通过uc_server实现会员同步整合教程.
会员数据整合是实现商城和论坛系统共享会员数据.论坛系统注册会员整合后可直接在商城登陆.现以本人社区为例.本人社区采用DZ最新的X3.1 商城采用的ECshop最近的V2.7.3 现在想把两个模板整合在 ...
- bzoj4557侦查守卫
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4557 树形DP.和“河流”有点像,也有一个类似“承诺”的东西. 就是用 f 表示当前节点向下 ...
- MyEclipse中将普通Java项目convert(转化)为Maven项目
在MyEclipse10中将Maven项目转成普通Java项目后,想将Java项目转成Maven项目,结果一下子傻眼了.根本就没有攻略中提到的config标签.仔细一看,喵咪的,人家用的是Eclips ...
- C#软件安全 反编译 加密与安全等等
我最近开发了一些C#语言的软件,但是由于这是一种解释型语言,也就是会转化成中间件语言,很容易就被反编译解密,包括exe和dll库等等,这时候我们真的需要使用一些技巧来将自己的成果进行加密,加壳等办法. ...
- RK3288 HDMI配置和调试
RK3288 最大输出分辨率为 3840x2160 HDMI 驱动代码位于 kernel/drivers/video/rockchip/hdmi/rockchip-hdmiv2 目录 1.设置默认输出 ...
- Windows10+CUDA8.0+VS2015+CUDNN5下配置caffe
[转]https://blog.csdn.net/zhj_matlab/article/details/69943869
- 以图文解锁 HTTPS原理***
我们先不了聊HTTP,HTTPS,我们先从一个聊天软件说起,我们要实现A能发一个hello消息给B: 如果我们要实现这个聊天软件,本文只考虑安全性问题,要实现: A发给B的hello消息包,即使被中间 ...
- Bootstrap组件系列之福利篇几款好用的组件(推荐)
引用 :http://www.jb51.net/article/87189.htm 一.时间组件 bootstrap风格的时间组件非常多,你可以在github上面随便搜索“datepicker”关键字 ...
- pagination实现分页功能
pagination.js: /** * pagination分页插件 */ ;(function($,window,document,undefined){ //配置参数 var defaults ...