1

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
    do
        echo "$param"
    done
}
$ params $(xclip -o)
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)"')
l0b0
  • 51,350
  • 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

2 Answers2

1

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)')
Ulrich Dangel
  • 25,369
  • 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 09:51
  • 1
    @l0b0 this is another issue and it is an awesome problem, see http://www.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
0

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

#!/bin/sh
vlc -- "$(xclip -o)"

and call that script from Awesome.