===== bash: "How To" ... utilize string substitutions ===== ^ string parameter substitution ^^^^^ ^operation^what^code^example using:\\ export TST='abcabcaa'^result from\\ (abcabcaa)^ |remove|first occurrence of substring '__xyz__' in string|STR=${STR/'__xyz__'}|echo ${TST/'bc'}|aabcaa\\ (abcabcaa)| |:::|substring '__xyz__' everywhere in string|STR=${STR//'__xyz__'}|echo ${TST//'bc'}|aaaa\\ (abcabcaa)| |:::|substring '__xyz__' at very beginning of string (prefix)|STR=${STR#'__xyz__'}|echo ${TST#'abca'}|bcaa\\ (abcabcaa)| |:::|substring '__xyz__' at very end of string (suffix)|STR=${STR%__xyz__}|echo ${TST%'bcaa'}|abca\\ (abcabcaa)| |:::|first __n__ characters|STR=${STR:__n__}|echo ${TST:2}|cabcaa\\ (abcabcaa)| |:::|last __n__ characters|STR=${STR:-__n__}|echo ${TST::-3}|abcab\\ (abcabcaa)| |extract|all characters after (!) position __n__\\ //(first char position: __n__=0)//|STR=${STR:__n__}|echo ${TST:1}|bcabcaa\\ (abcabcaa)| |:::|__m__ characters after (!) position __n__|STR=${STR:__n__:__m__}|echo ${TST:1:5}|bcabc\\ (abcabcaa)| |:::|characters after (!) position __n__ until end of string minus __m__|STR=${STR:__n__:-__m__}|echo ${TST:1:-1}|bcabca\\ (abcabcaa)| |convert|to upper case|STR=${STR^^}|echo ${TST^^}|ABCABCAA| |:::|to lower case|STR=${STR,,}|echo ${TST,,}|abcabcaa| |cut|from begin of string to first end of substring '__xyz__'|STR=${STR#*'__xyz__'}|echo ${TST#*'bc'}|abcaa\\ (abcabcaa)| |:::|from begin of string to last end of substring '__xyz__'|STR=${STR##*'__xyz__'}|echo ${TST##*'bc'}|aa\\ (abcabcaa)| |:::|from last occurrence of substring '__xyz__' to end of string|STR=${STR%'__xyz__'*}|echo ${TST%'bc'*}|abca\\ (abcabcaa)| |:::|from first occurrence of substring '__xyz__' to end of string|STR=${STR%%'__xyz__'*}|echo ${TST%%'c'*}|ab\\ (abcabcaa)| //work in progress//