Programming Reference/Librarys
Question & Answer
Q&A is closed
This is an old revision of the document!
operation | what | code | example using: export TST='abcabcaa' | result from abcabcaa |
---|---|---|---|---|
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} | cabcaa | |
last n characters | STR=${STR:-n} | echo ${TST::-3} | abcab | |
extract | all characters after position n | STR=${STR:n} | echo ${TST:1} | bcabcaa |
m characters after position n | STR=${STR:n:m} | echo ${TST:1:5} | bcabc | |
characters after position n until end of string minus m | STR=${STR:n:-m} | echo ${TST:1:-1} | bcabca |