linux + tput:$TERM 没有值并且没有指定 -T

yae*_*ael 1 linux colors terminal environment-variables tput

我在 bash 脚本中使用 tput 命令来为文本着色

作为

tput setaf 2
Run Code Online (Sandbox Code Playgroud)

当我从腻子或控制台运行脚本时,一切正常

但是当我运行一些通过 SSH 运行脚本的外部 WIN 应用程序引擎时,我们在 tput 上收到以下错误

tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
Run Code Online (Sandbox Code Playgroud)

请建议我的 bash 脚本中需要设置什么(ENV 或其他)才能使用 tput 命令?

Tho*_*key 5

通过 连接时ssh,环境变量可能会(也可能不会)传递到远程应用程序。另外,“WIN 应用程序引擎”很可能TERM根本不设置。

如果TERMputty(或者xterm,就此而言),它们具有相同的效果:

tput setaf 2
tput -T putty setaf 2
Run Code Online (Sandbox Code Playgroud)

因为使用的控制序列setaf是相同的。同样,如果TERMlinux,这些是相同的

tput setaf 2
tput -T linux setaf 2
Run Code Online (Sandbox Code Playgroud)

用于使用ANSIsetaf (x3.64) 转义序列将前景(文本)设置为特定值。您使用的大多数终端都会这样做——或者有些终端无法识别任何这些转义序列。由于未提及该应用程序,因此您必须进行实验以查看“WIN 应用程序引擎”是否可以识别这些转义序列。如果是这样,它可能使用相同的ANSI转义,所以你可以这样做

tput -T xterm setaf 2
Run Code Online (Sandbox Code Playgroud)

(当然,putty、linux 和 xterm 之间还有其他区别)。