Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 2
    Part of the problem is coming from storing the command in a variable before executing it; see BashFAQ 050: I'm trying to put a command in a variable, but the complex cases always fail! Commented Feb 17, 2013 at 16:03
  • 1
    And the the problem with the second approach also has its root in the intricacies of Bash’s argument parsing: "$@" expands to a list of several word arguments, which is not what you want. Use "$*" instead, which expands to a single word argument. See the BashWiki articles Arguments and Quotes. @GordonDavisson, care to turn your comment into an answer? Commented Mar 21, 2013 at 0:14
  • @kopischke: Actually, I don't think I have anything to add to @Lauri Ranta's answer (which I've already voted for) -- she includes the $* trick, and also includes a run handler trick (which makes it more robust about special characters in the message) that I didn't think of. Commented Mar 21, 2013 at 1:25
  • @GordonDavisson I agree Lauri’s answer is neat, but it does not explain why OP’s approaches are failing (literal vs. syntactical quoting, word splitting on parameter expansion of "$*" vs. "$@"), which you pointed out. Commented Mar 21, 2013 at 8:22