0

Environment: Ubuntu 18.04. I'm attempting to start an xfce4-terminal with multiple tabs. The number of tabs will change hence I have to build an string will all the argument passed to xfce4-terminal.

#!/bin/bash
xfce4Args="--disable-server --hold --minimize" 
Acq="ls -R"
OPTIONS="-R"
Ser="--title=Pre --command=ls ${OPTIONS}"
xfce4-terminal  ${xfce4Args} --title="Acq" --command="${Acq}" \
--tab ${xfce4Args} "${Ser}" 

The argument to --command must be between double quote to make sure xfce4-terminal see it one argument event though it might contains spaces. So for --command="${Acq}" this works fine. For the second tab, ${Ser} does not work. If Ser does not contain the --title=Per its space separator, it works, because "${Ser}" becomes one argument that is understood. But with the --title=Per the arguments are no longer understood as separate arguments.

Even with my reading on the subject I have not been able to come up with a working solution. I was going to attempt using eval but seems too desparated and decided asking around .

Mario
  • 302
  • 1
  • 8
  • 2
    See [BASH FAQ](https://mywiki.wooledge.org/BashFAQ) number 50 – glenn jackman May 06 '19 at 18:00
  • Use an array. See [this](https://stackoverflow.com/questions/7454526/variable-containing-multiple-args-with-quotes-in-bash) and many other similar questions. – Gordon Davisson May 06 '19 at 19:02
  • Gordin, thanks, Sorry I forgot to mention that can't use arrays. Compatibility with other shell that don't have array is required. – Mario May 07 '19 at 18:18
  • @Mario Building commands dynamically without arrays is messy at best. One possibility is to treat the script's own argument list as a sort-of-array, e.g. adding elements to it with `set -- --title=Pre --command="ls ${OPTIONS}"` and then using it with `... --tab ${xfce4Args} "$@"`. `eval` is also a possibility, but it provides opportunities for things to go wrong in really bizarre ways. – Gordon Davisson May 07 '19 at 23:35
  • Isn't it schizophrenic to expect `"--title=Pre --command=ls ${OPTIONS}"` to be separated at the first space, but not at the second one? – Armali May 08 '19 at 11:39

0 Answers0