User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







bash:how_to:string_substitutions

This is an old revision of the document!


bash: "How To" ... utilize string substitutions

string parameter substitution
operationwhatcodeexample using:
export TST='abcabcaa'
result from
abcabcaa
removefirst occurence of substring 'xyz' in stringSTR=${STR/'xyz'}echo ${TST/'bc'}aabcaa
substring 'xyz' everywhere in stringSTR=${STR//'xyz'}echo ${TST//'bc'}aaaa
substring 'xyz' at very beginning of string (prefix)STR=${STR#'xyz'}echo ${TST#'abca'}bcaa
substring 'xyz' at very end of string (suffix)STR=${STR%xyz}echo ${TST%'bcaa'}abca
first n charactersSTR=${STR:n}echo ${TST:2}cabcaa
last n charactersSTR=${STR:-n}echo ${TST::-3}abcab
extractall characters after (!) position n
(first char position: n=0)
STR=${STR:n}echo ${TST:1}bcabcaa
m characters after (!) position nSTR=${STR:n:m}echo ${TST:1:5}bcabc
characters after (!) position n until end of string minus mSTR=${STR:n:-m}echo ${TST:1:-1}bcabca

work in progress

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
bash/how_to/string_substitutions.1533270250.txt · Last modified: 2024/02/16 01:02 (external edit)

Impressum Datenschutz