'Why is it neceesary to add single quote inside the double quote in the bind command?

I want to bind function key f5 with a play action ,when f5 pressed ,the sample.mp4 played by ffplay:

bind -x '"'$(tput kf5)'":"ffplay /tmp/sample.mp4"'

If write it as below:

bind -x '"$(tput kf5)":"ffplay /tmp/sample.mp4"'

The bind action can't take effect.

Why to add single quote inside double quote "'$(tput kf5)'" instead of "$(tput kf5)" ?



Solution 1:[1]

You can use here-doc to avoid quoting issues (or to have more readable code):

bind -x "$(cat << EOF
"$(tput kf5)":"ffplay /tmp/sample.mp4"
EOF
)"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Philippe