Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Based on a suggestion, I've now got the following call in rc.lua:

awful.util.spawn_with_shell('vlc $(xclip -o)')

How do I ensure that the output of xclip is escaped so that space characters are not taken as parameter separators? For example, if I select the string "foo bar" (without the quotes) and press Mod4+v VLC complains about being unable to open both "foo" and "bar".

To illustrate, in a shell context I would validate the issue as follows:

$ params() {
    for param
        echo "$param"
$ params $(xclip -o)

And fix it like this:

$ params "$(xclip -o)"
params "$(xclip -o)"

However, if I change the Lua call to this, it does nothing:

awful.util.spawn_with_shell('vlc "$(xclip -o)"')
share|improve this question
Either pipe the xclip output through sed and escape the “unsafe” letters manually or write a small python script and use one of the shell escaping libraries. – Marco Mar 16 '13 at 17:09

There is no need as the output of xclip will not be evaluated by the shell again; The shell will execute vlc and sets the parameter to the value of xclip -o without evaluating the output.

To test it yourself you can run things like:

echo $(echo '`ls`')
echo $(echo '$PATH')
echo $(echo '$(echo foobar)')
share|improve this answer
You're right. I've amended the question to only ask about space characters, since whitespace expansion is still an issue. – l0b0 Mar 17 '13 at 9:51
@l0b0 this is another issue and it is an awesome problem, see mail-archive.com/awesome-devel@naquadah.org/msg07931.html - just write a script and call the script – Ulrich Dangel Mar 17 '13 at 11:16

Always put variable substitutions and command substitutions in double quotes. This suppresses word splitting and globbing on the result of the substitution. This should work:

awful.util.spawn_with_shell('vlc -- "$(xclip -o)"')

I can't explain why it does nothing, there may be some subtlety of Lua that escapes me. As a workaround, you could write a one-liner script

vlc -- "$(xclip -o)"

and call that script from Awesome.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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