bashfontsxterm

Weird behavior with executing /usr/bin/xterm from a bash script and specifying a font


On Ubuntu 22.04, the following command when run from the prompt works as expected (i.e. it opens an xterm with the specified font)

$ /usr/bin/xterm -fa "Ubuntu Mono" -fs 20

But the following Bash script produces the error "No absolute path found for shell: Mono"

#!/usr/bin/bash
T="/usr/bin/xterm"
F='-fa "Ubuntu Mono" -fs 20'
${T} ${F}

I've played with different quoting but have been unable to resolve the problem. Unfortunately I do need to use 'xterm' in this case.


Solution

  • EDIT: It's safer to pick @choroba's answer.

    That's because how Bash interprets the variables. Strace shows this:

    $ strace ${T} ${F}
    execve("/usr/bin/xterm", ["/usr/bin/xterm", "-fa", "\"Ubuntu", "Mono\"", "-fs", "20"], 0x7fff90ae1d48 /* 38 vars */) = 0
    

    If you wrap it with "eval" it works:

    #!/usr/bin/bash
    T="/usr/bin/xterm"
    F='-fa "Ubuntu Mono" -fs 20'
    eval "${T} ${F}"