At the moment, this is just a dumping ground for useful tidbits I find / need in my daily work. At some point I will get around to organizing and formalizing.
Parameter Expansion
Slice a string
a="teleport"
b=${a:4:7}
echo $b
> port
Replace a portion of a string
The pattern is ${parameter/pattern/string}
to replace the first occurence of pattern
with string
or ${parameter//pattern/string}
to replace all occurrences.
s="string"
t=${s/t/p}
echo $t
> spring