bashwhitespacefontconfig

Bash. Passing a variable containing spaces


I am using dmenu list selection tool on linux. Let's assume my typical invocation goes like that:

ls | dmenu $DMENU_OPTIONS 

Settings from .dmenurc:

DMENU_FN="Liberation:size=16"
DMENU_OPTIONS="<...> -fn $DMENU_FN"

Then, I have use some quicklaunch script based on dmenu. It takes dmenu options with this line:

dmenu_cmd="dmenu $DMENU_OPTIONS"

Now, I switch font name to Liberation Mono and the font piece is now recognised as two parameters for one option. Dmenu gets syntax error. I couldn't get around that using quotes or backslashes. So there is a variable with a spacebar which should be passed to another variable.


Solution

  • if you split font name from other arguments like the example below and use double quotes, it will work:

    DMENU_FONT="Dejavu Sans Mono:medium:size=18"
    DMENU_OPTS="-nb #191919 -nf #FF0000 -sb #FF9318 -sf #191919"
    ls | dmenu -fn "$DMENU_FONT" $DMENU_OPTS
    

    Notice that DMENU_FONT is within double quotes while DMENU_OPTS is not, as the goal is returning font name as a single value, and the second variable as multiple arguments.

    Hope it helps.