When trying to extend a script, for some reason, if a sed expression is inside a variable it won't run.
Minimal example:
echo lorem >> /tmp/testsed
CMD="sed --debug -i.bak -e 's/lorem/ipsum/' /tmp/testsed"
$CMD
results in:
sed: -e expression #1, char 1: unknown command: `''
I've looked at a few (1, 2 - not quite the same, 3 and 4 - solves the issue, but not ideal ) similar posts, but none solved the issue.
For now I'm using eval
(like 4 initially suggests), but it's not an ideal solution; also creating a function is not an option.
I feel like it's related to having to escape some characters on the expression, but from my tests I could not find which.
This sed expression is set as a action that another script executes after some specific action.
$CMD
– αғsнιη Apr 30 '21 at 19:15