shell expansion 笔记

9月 5, 2017 |

Brace Expansion

mkdir ./{old,new,dist,bugs} #generate ./old, ./new, ./dist, ./bugs
echo {00..10..2}? #generate 00 02 04 06 08 10 , from 00 to 10 step=2

Tilde Expansion

~ #The value of $HOME
~+/foo #$PWD/foo

Shell Parameter Expansion

${parameter} #parameter's value
${#parameter} #length of parameter
${!prefix@} #variable name begin with prefix
array[0]=01234567890abcdefgh
echo ${array[0]:7} #substring from index 7 to end
${parameter/pattern/string} #replace match pattern parts with string
${parameter^pattern} #change match pattern parts's case in parameter

Command Substitution

$(command) or ‘command‘

Arithmetic Expansion

$(( expression ))

Word Splitting

not within double quotes

Filename Expansion

can be disabled by set -f
echo * #expand to all files in current directory

Posted in: Linux

Comments are closed.