Replacing Variables with Bash

$(var:pos[:len]) # extract substr from pos (0-based) for len

$(var/substr/repl) # replace first match
$(var//substr/repl) # replace all matches
$(var/#substr/repl) # replace if matches at beginning (non-greedy)
$(var/##substr/repl) # replace if matches at beginning (greedy)
$(var/%substr/repl) # replace if matches at end (non-greedy)
$(var/%%substr/repl) # replace if matches at end (greedy)

${#var} # returns length of $var
${!var} # indirect expansion

Related Posts:

  • No Related Posts
This entry was posted in Web Development and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *