Linux Mint .profile TERM 變數未設定

Linux Mint .profile TERM 變數未設定

我的 .profile 檔案中有一個自訂腳本,新增了程式碼,但沒有刪除任何內容,但它仍然回覆錯誤TERM ENVIRONMENT VARIABLE NOT SET。但是,如果我echo $TERM在啟動後在終端中運行該命令,它將設置為xterm-256color.我甚至願意抑制錯誤而不是解決它,因為它在啟動後不會影響我的電腦。

這是 .profile 中的腳本:

clear
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi


# --- EVERYTHING ABOVE HERE IS DEFAULT AND NOT CHANGED ---


wget -q --spider http://google.com
if [ $? -eq 0 ]; then
    (
     echo )
    else
    (
    echo Aquiring Internet Connection . . .
    sleep 6)
    fi
wget -q --spider http://google.com
if [ $? -eq 0 ]; then
    (
     echo )
    else
    (
    sleep 5)
    fi

wget -q --spider http://google.com
if [ $? -eq 0 ]; then
    echo ==========================================================================================================================================
    echo WELCOME LUKAKA                                     LOCAL WEATHER REPORT    VIA WTTR.IN                                      Running XFCE
    echo ==========================================================================================================================================
    curl wttr.in
    echo ==========================================================================================================================================
    echo
    echo -e "\033[1;32mStatus for play.wildcraftmc.com [Wildcraft Survival+ Server]   \033[0m" 
    mcstatus play.wildcraftmc.com status >wildcraft.txt
    sed -n 1p wildcraft.txt
    tail -n -1 wildcraft.txt
    echo ==========================================================================================================================================
    echo -e "\033[1;32mStatus For Mc.Starlegacy.Net [Starlegacy Space Survival]   \033[0m" 
    mcstatus mc.starlegacy.net status >Star-Legacy.txt
    sed -n 1p Star-Legacy.txt
    tail -n -1 Star-Legacy.txt
    echo ==========================================================================================================================================
    echo -e "\033[1;32mStatus For Jectile.com [Shoota COD Server]   \033[0m" 
    mcstatus Jectile.com status >Star-Legacy.txt
    sed -n 1p Star-Legacy.txt
    tail -n -1 Star-Legacy.txt
    echo ==========================================================================================================================================
    rm Star-Legacy.txt
    rm wildcraft.txt
else
    echo Connection Failed.
fi

echo -n "Would you like to start the GUI (y/n)? "
old_stty_cfg=$(stty -g)
stty raw -echo ; answer=$(head -c 1) ; stty $old_stty_cfg # Careful playing with stty
if echo "$answer" | grep -iq "^y" ;then
    sudo systemctl start lightdm
    onedrive-d start
    xinput set-prop 11 317 -1
else
    echo No
    echo -e "\033[0;33mskipping GUI. The following service(s) will not run: onedrive-d, lightdm, Minecraft-Lukaka, xinput 11.\033[0m"
    fi

這是錯誤訊息:呃\

對於上下文,我的腳本所做的是檢查互聯網連接,如果有,它會獲取 wttr.in(天氣)並使用官方 Minecraft 工具來檢查某些伺服器上的狀態。

答案1

因此,一旦您的腳本詢問您是否要啟動 GUI,如果您回答“是”,它就會再執行 3 個命令:

sudo systemctl start lightdm

onedrive-d start

xinput set-prop 11 317 -1

現在,如果您知道這些錯誤是無害的,則可以2>/dev/null在導致錯誤的命令之後使用以下命令將它們重定向為無害,例如

sudo systemctl start lightdm 2>/dev/null

但是,更建議依序運行每個命令,檢查顯示的錯誤並在可能的情況下修復它們。

答案2

在列印訊息或執行需要終端的命令之前,您應該檢查是否正在終端機中執行。例如,可以使用以下方法來完成此操作:

if [ -t 1 ] # check if stdout is a terminal
then
  # in a TTY, do stuff
fi

GUI 登入過程來源/etc/profile~/.profile以便設定您可能需要的任何環境變數。但這種採購不是在終端機中完成的,因此TERM沒有設定。當您開啟終端並執行 時echo $TERM,終端已設定TERM由它啟動的進程,因此您會得到一個值。

在我看來,您應該包裝在上面給出的檢查中添加的所有內容if,因為在 GUI 中運行時,它們都不是特別相關的。

相關內容