Hi,
I've known several operations we can do to variables in shell, e.g:
1) "#" & "##" operation
with ${var#pattern}, we remove "pattern" in the head of ${var}. "*" could be used in the pattern to match everything. And the difference between "#" and "##" is that, "##" will remove the longest match substring while "#" removes the shortest. For example,
var=brbread
${var##*br} // ead
${var#*br} // bread
2) "%" & "%%" operation
with ${var%pattern}, we remove "pattern" at the end of ${var}. Of course, "%%" indicates longest match while "%" means the shortest. For example,
var=eadbreadbread
${var%%*br} // eadbreadbread
${var%%br*} // ead
${var%br*} // eadbread
3) "/" operation
with ${var/haha/heihei}, we replace "haha" in $var with "heihei". For example,
var=ihahai
${var/haha/heihei/} / iheiheii
I'm just curious wether or not we can make more operations to variables other than above ones?
Thanks.