Programming Reference/Librarys
Question & Answer
Q&A is closed
This is an old revision of the document!
operation | what | code | example export TST=“abcabcaa” | result |
---|---|---|---|---|
remove | first occurence of characters 'xyz' in string | STR=${STR/'xyz'} | echo ${TST/'bc'} | aabcaa |
all characters 'xyz' in string | STR=${STR'xyz'}|echo ${TST'bc'} | aaaa | ||
characters 'xyz' at end of string | STR=${STR/%x} | echo ${TST%'bcaa'} | abca | |
first n characters | STR=${STR:n} | echo ${TST:2} | ||
last n characters | STR=${STR:-n} | echo ${TST::-3} | ||
extract | all characters after position n | STR=${STR:n} | echo ${TST:1} | |
m characters after position n | STR=${STR:n:m} | echo ${TST:1:5} | ||
characters after position n until end of string minus m | STR=${STR:n:-m} | echo ${TST:1:-1} |