Replace pattern in string
suggest changeFirst match:
$ a='I am a string'
$ echo "${a/a/A}"
I Am a string
All matches:
$ echo "${a//a/A}"
I Am A string
Match at the beginning:
$ echo "${a/#I/y}"
y am a string
Match at the end:
$ echo "${a/%g/N}"
I am a strinN
Replace a pattern with nothing:
$ echo "${a/g/}"
I am a strin
Add prefix to array items:
$ A=(hello world)
$ echo "${A[@]/#/R}"
Rhello Rworld
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents