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脚本,其能完成的功能往往令 ...
随机推荐
- 获得消息的x,y的窗口内坐标(包括边框和titlebar高度
rectWindow = D2D.GetWindowRect(self.hwnd)#窗口大小 rectClient = D2D.GetWindowRect(self.hwnd,True)#客户区大小 ...
- Python中super()和__init__()方法
采用新式类,要求最顶层的父类一定要继承于object,这样就可以利用super()函数来调用父类的init()等函数, 每个父类都执行且执行一次,并不会出现重复调用的情况.而且在子类的实现中,不用到处 ...
- 如何批处理多个MySQL文件
@echo off CHCP 65001 --设置cmd编码for %%i in (E:\sql\*.sql) do ( --多个MySQL SQL文件的存放目录echo excute %%i ...
- 嵌入式无法使用QAudioDeviceInfo类
修改: 1.修改pro文件 增加 QT += multimedia 2.修改Makefile文件,LIBS = $(SUBLIBS) -L/opt/qt-4.8.5/lib -lQtMulti ...
- eclipse git 开发操作流程
1.eclipse git 开发操作流程 1.1流程简介 1)master主分支,当开发版本得到了充分的验证之后,才能将分支合入master,master为可产品化发布的状态. 2)develop分支 ...
- Sql Server 2012 存储过程的调试
[一]Sql Server 关于存储过程调试SQL2000是在查询分析器中的对象浏览器中选中需要调试的存储过程,右键----调试---输入参数开始调试.sqlserver2008中则完全不同,变成了必 ...
- java 的一个hellow word 代码解释
/* This is a simple Java program. Call this file "Example.java". */(上面是注释的方法) class Exampl ...
- javascript slice array to num subarray
var data = ['法国','澳大利亚','智利','新西兰','西班牙','加拿大','阿根廷','美国','0','国产','波多黎各','英国','比利时','德国','意大利','意大利 ...
- 如何利用R包qqman画曼哈顿图?
如何利用R包qqman画曼哈顿图? 2017-07-10 lili 生信人 众多周知,R语言提供了各种各样的包,方便实现我们的目的,下面给大家介绍一个可以便捷的画曼哈顿图的包:qqman instal ...
- 转:Ubuntu下下载工具安装--uget+aria2
原文地址:http://burner1024.blog.163.com/blog/static/17447800420126191858424/ Windows下的下载工具--迅雷,之所以下载速度快, ...