How can I escape quotes in .xbindkeysrc commands? Neither of those work.

"pacmd dump|awk --non-decimal-data '$1~/set-sink-volume/{system ("pacmd "$1" "$2" "$3+2500)}'"

"pacmd dump|awk --non-decimal-data '\$1~/set-sink-volume/{system ("pacmd "\$1" "\$2" "\$3+2500)}'"

"pacmd dump|awk --non-decimal-data '\$1~/set-sink-volume/{system (\"pacmd \"\$1\" \"\$2\" \"\$3+2500)}'"

"pacmd dump|awk --non-decimal-data '$1~/set-sink-volume/{system (\"pacmd \"$1\" \"$2\" \"$3+2500)}'"

(The commands raises the PulseAudio volume level)


There's two separate issues here, and I'll try to address both.

The first is how to correctly quote a command in .xbindkeysrc.

All you have to do is take a command that works in bash, then put double quotes around it.

For example, for a command with a space in it, you'd have to run

"/home/user/My Programs/progname"


/home/user/My\ Programs/progname

in bash.

Which means you need

""/home/user/My Programs/progname""


"/home/user/My\ Programs/progname"

in your .xbindkeysrc.

Technically what's happening is that xbindkeys removes the outermost pair of double quotes, then runs the remaining string using sh -c.

In your example, the command

pacmd dump|awk --non-decimal-data '$1~/set-sink-volume/{system ("pacmd "$1" "$2" "$3+2500)}'

works fine in bash, so I think the problem is elsewhere.

Try running xbindkeys with the -v option, which makes xbindkeys run in the foreground, so you can see any errors on your terminal.

In my case, it shows the underlying cause is not bad quoting, but pacmd giving an error

No PulseAudio daemon running, or not running as session daemon.

but if you have PulseAudio working, I think you need to change pacmd to pactl, because the man page says that pacmd doesn't take arguments, and several other examples on the web show using pactl for this purpose.

  • 2
    Thanks, putting the command in double quotes with no escaping at all worked :) – Danilo Bargen Nov 6 '12 at 12:25

As a workaround, create a shell script ~/bin/mychangevolume with the commands non-escaped as they would appear on the command line. Something like

pacmd dump | awk --non-decimal-data '$1~/set-sink-volume/{system ("pacmd "$1" "$2" "$3'$incr')}'"

Then call this script from .xbindkeysrc

"mychangevolume +2500"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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