I ran into the most annoying problem that occurs in a variable PWDwhen the current path contains a space. My code looks something like this:
mycommand |sed -E '
s|mystuff|replacement| ;
s|'$(pwd)'|replacement| ;
'
This works fine if the current path does not contain a space. If so, $(pwd)expand to
'mypath / with space'
not just mypath / with space
This will cause the sed expression to get corrupted (due to extra quotes):
sed: 1: "s | mypath / with": unterminated substitute pattern
I have noticed that it does not help to expand pwd follows: ${PWD//\'/}.
Any ideas on how this can be resolved?
source
share