Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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)"')
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
add comment

2 Answers

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
1  
@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
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

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.