I am trying to store the start of a sed command inside a variable like this:
sedcmd=\"sed -i \'\' \"
Later I then execute a command like so:
It works when the command is only one word long:
$ LS=ls
$ $LS
But in your case, the shell is trying the execute the program sed -i ''
, which does not exist.
The workaround is to use $SHELL -c
:
$ $SHELL -c "$LS"
total 0
(Instead of $SHELL
, you could also say bash
, but that's not entirely reliable when there are multiple Bash installations, the shell isn't actually Bash, etc.)
However, in most cases, I'd actually use a shell function:
sedcmd () {
sed -i '' "$@"
}