this works for me:

CMD="ls -la"

while this always fails:

CMD="sed -e 's|abc|abc|g' file"

with the error message:

sed: -e expression #1, char 1: unknown command: `''

That's because when you enter the command on the command line, shell runs "expansions" on it. The last step is "Quote Removal", but it only removes quotes that weren't a result of any expansion. (See EXPANSIONS in man bash for details.) Here, the quotes are part of the variable expansion, so they're not removed.

You can enter the substitution without quotes to make it work:

cmd='sed -e s|abc|abc|g file'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.