명령으로서의 변수

명령으로서의 변수

터미널 이름으로 변수를 설정하고 해당 변수를 사용하여 터미널을 전체 화면으로 열고 싶습니다. 그것은 다음과 같습니다:

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 &

이 작업을 어떻게 수행합니까?

답변1

단순히 $( )아무것도 교체하지 마십시오.

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 &

$( )명령을 실행하고 출력을 변수나 명령줄에 붙여넣는 데 사용됩니다.

위의 코드는 실행되지 않을 수 있습니다. foo 터미널 중 하나가 정의되지 않은 경우 제안하겠습니다.

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

답변2

내가 아는 한 xterm대부분의 Linux 기반 OS에서 사용할 수 있습니다.
어쨌든 사용된 터미널은 변수에서 발견됩니다 $TERM.

관련 정보