我的shell脚本如何确定它是否在真正的shell中?

时间:2011-03-29 10:30:55

标签: bash terminal

我有一个在我的个人终端和CI环境中运行的shell脚本。在CI环境中,python调用确定shell高度/宽度返回有趣的值。

我想做点什么:

if (I am running in shell context)
    determine height/width of terminal
else
    don't
fi

如何在bash脚本中表达这种情况?

1 个答案:

答案 0 :(得分:6)

检查标准输入是否为tty设备。

在sh / bash中:

if [ -t 0 ]; then

在Python中:

if os.isatty(sys.stdin):