One, variable and :- with
Bin= ' DirName "${bash_source-$0}" ' Bin= ' CD "$bin"; PWD ' default_libexec_dir= "$bin"/.. /libexeclibexec_dir= ' #变量set了, but is null libexec_dir=${libexec_dir:-$DEFAULT _libexec_dir}echo $LIBEXEC _dir
${PARAMETER:-WORD}
${PARAMETER-WORD}
If the parameter PARAMETER
is unset (never were defined) or null (empty), this one expands WORD
to, otherwise it expands to th E Value of PARAMETER
.
If you omit :
the (colon), like shown in the second form, the default value is only used when the parameter was UN Set, not if it was empty. For the second case, the parameter variable is not set to use the word value
Second, the role of variable and # #或者percent
There is a variable foldername=569_20180118150257, if you want to get _ before the 569 or the next 20180118150257, how to do it?
foldername=569_20180118150257 Echo ${foldername##*_} #返回20180118150257 # equivalent to echo ${foldername# #569_} echo ${foldername %%_*} #返回569 # equivalent to echo ${foldername%%_20180118150257}
From the above can be seen # #或者 percent with the variable is to delete the matching part, # #是从开始匹配569_, and delete 569_,%% is from the back match _*, and delete _*
Note that two # #或者 percent of a percent represents the longest match, with # or% differences to look at the following example:
Filename= "Sequencing.fq.gz" Echo ${filename##*.} #返回gzecho ${filename#*.} #返回fq. GZ Echo ${filename%%.*} #返回sequencingecho ${filename%.*} #返回sequencing. Fq
Third,bash script gets its own path method
Bin= ' DirName "${bash_source[0]}" ' #脚本相对于当前目录的路径, is the relative path bin= ' CD ' $bin "; PWD '
Shell's operations on variables