Linux Mint .profile TERM 变量未设置

Linux Mint .profile TERM 变量未设置

我的 .profile 文件中有一个自定义脚本,添加了代码,没有删除任何内容,但它仍然会返回错误。但是,如果我在启动后在终端中TERM ENVIRONMENT VARIABLE NOT SET运行该命令,它会被设置为。我甚至可以抑制错误而不是解决它,因为它在启动后不会影响我的电脑。echo $TERMxterm-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 中运行时,它们都不是特别相关的。

相关内容