Bash remove prefix from a string variable

Remove a leading string from a variable. The string after the number sign is removed from the variable.

$ mkdir -p /tmp/path/to/something/
$ cd /tmp/path/to/something/
$ echo $PWD
/tmp/path/to/something
$ echo "${PWD#/tmp}"
/path/to/something
Did this help you? Please let me know with a comment. Thank you
Posted .

Comments (RSS)

Leave a comment