This shows you the differences between two versions of the page.
|
bash:how_to:start [2018/08/02 22:31] Rob Stroess |
— (current) | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ===== bash: "How To"===== | ||
| - | ^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}|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 | ||