I am trying to run a command from a variable in shell script. The shell being used is bash shell.
The file exp
contains:
abcdef
Executing the following command:
sed s/b/\ / exp
...produces the output:
a cdef
But executing:
cmd="sed s/b/\ / exp"
echo $cmd
$cmd
...produces the following error:
sed s/b/\ / exp
sed: -e expression #1, char 5: unterminated `s' command
I can see that adding eval
in front of the execution works. But I cannot understand why. Can you explain why one method is working and the other is not working?