Reputation: 640
I have a path that is stored in a variable
$FULLPATH="/this/is/the/path/to/my/file.txt"
I also have another variable containing a partial path
$PARTIAL="/this/is/the/"
I want to remove the partial path from the full path so that I am left with:
path/to/my/file.txt
What's the best way to do this?
Upvotes: 1
Views: 1199
Reputation: 12976
Here's a little more detail to Mr. Klatchko's excellent answer:
$ FULLPATH="/this/is/the/path/to/my/file.txt"
$ PARTIAL="/this/is/the/"
$ echo ${FULLPATH#${PARTIAL}}
path/to/my/file.txt
Upvotes: 3
Reputation: 799150
If you're sure that $PARTIAL
is an actual path:
result="${FULLPATH#$PARTIAL}"
result="${result#/}"
Upvotes: 1
Reputation: 76581
Use bash's #
pattern matching operator:
${FULLPATH#${PARTIAL}}
Upvotes: 3