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
  • 50,672
  • 41
  • 197
  • 360
  • 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,079
  • 3
  • 80
  • 80
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.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175