Variable como comando

Variable como comando

Quiero configurar una variable con el nombre del terminal y usar esa variable para abrir el terminal en pantalla completa. Sería algo como:

if [ "$DESKTOP" = "gnome" ]; then
    if command_exists gnome-terminal; then
        terminal=$(gnome-terminal)
    fi
elif [ "$DESKTOP" = "mate" ]; then
    if command_exists mate-terminal; then
        terminal=$(mate-terminal)
    fi
fi
$terminal --working-directory="$HOME/code/" --window --full-screen &

¿Cómo hago que esto funcione?

Respuesta1

simplemente reemplácelo $( )por nada.

if [ "$DESKTOP" = "gnome" ]; then
    if command_exists gnome-terminal; then
        terminal=gnome-terminal
    fi
elif [ "$DESKTOP" = "mate" ]; then
    if command_exists mate-terminal; then
        terminal=mate-terminal
    fi
fi
$terminal --working-directory="$HOME/code/" --window --full-screen &

$( )Se utiliza para ejecutar un comando y pegar el resultado, ya sea en una variable o en la línea de comando.

Es posible que el código anterior no se ejecute, si alguno de los terminales foo no está definido, sugeriría

noterminal=true
if [ "$DESKTOP" = "gnome" ]; then
    if command_exists gnome-terminal; then
        gnome-terminal --working-directory="$HOME/code/" --window --full-screen &
        noterminal=false
    fi
elif [ "$DESKTOP" = "mate" ]; then
    if command_exists mate-terminal; then
        mate-terminal --working-directory="$HOME/code/" --window --full-screen &
        noterminal=false
    fi
fi
if $noterminal
then
   echo unable to find terminal 
   ## or other GUI alert system.
   ## or xterm as per mmmint sugestion
fi

Respuesta2

Hasta donde yo sé, xtermestá disponible en la mayoría de los sistemas operativos basados ​​en Linux.
En cualquier caso el terminal utilizado se encontrará en la $TERMvariable.

información relacionada