I have a tenuous grasp of Bash scripting and piping, and have encountered a situation where my limited-experience-based expectation conflicts with reality. I want to remove a substring (specifically a suffix) from a Bash variable using sed. The string and substring are both Bash variables.
> foo1=foo.cpp
> foo2=/main/bar/foo.cpp
> foo3=$(echo $foo2 | sed 's/$foo1//')
> echo $foo3
/main/bar/foo.cpp
If I use a hardcoded string in the sed expression in place of $foo1, the expression behaves as desired:
> foo4=$(echo $foo2 | sed 's/foo\.cpp//')
> echo $foo4
/main/bar/
Can anyone point out what I'm missing to make the foo3 evaluation work such that "foo.cpp" is deleted? Thank you.