bash 如何删除“未设置TERM环境变量”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19425727/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to remove "TERM environment variable not set"
提问by rohini
I am having a script runonce.sh who calls another script setup.sh through cron. We consider this case as ideal case where "TERM environment variable not set." is seen in output of runonce.sh script.
我有一个脚本 runonce.sh,它通过 cron 调用另一个脚本 setup.sh。我们认为这种情况是“未设置 TERM 环境变量”的理想情况。在 runonce.sh 脚本的输出中可以看到。
Now I am facing a problem that another third simple script - upgradeAndTest.sh when calls setup.sh, that time also "TERM environment variable not set." is seen in output of upgradeAndTest.sh script. Why is so..?
现在我面临一个问题,即调用 setup.sh 时的另一个第三个简单脚本 - upgradeAndTest.sh,当时也“未设置 TERM 环境变量”。在 upgradeAndTest.sh 脚本的输出中可以看到。为什么会这样..?
Also, if I redirect stderr of setup.sh to stdout in calling script then also "TERM environment variable not set." displays on console.
另外,如果我在调用脚本中将 setup.sh 的 stderr 重定向到 stdout,那么也会“未设置 TERM 环境变量”。显示在控制台上。
Can any one help me to remove this line from stdout of calling script..?
谁能帮我从调用脚本的标准输出中删除这一行..?
回答by Jonathan Leffler
Running a program that demands a terminal via cron
can lead to problems; it won't have a terminal when it is run by cron
.
运行需要通过终端的程序cron
可能会导致问题;运行时它不会有终端cron
。
In case of doubt, though, ensure that the variable is set in the script, by adding a line:
但是,如果有疑问,请通过添加一行来确保在脚本中设置了变量:
export TERM=${TERM:-dumb}
If the environment variable TERM
is already set, this is a no-op. If it is not, it sets the terminal to a standard one with minimal capabilities — this satisfies the program that complains about TERM
not being set.
如果环境变量TERM
已经设置,这是一个空操作。如果不是,它会将终端设置为具有最少功能的标准终端——这满足了抱怨TERM
未设置的程序。