我有一个在我的个人终端和CI环境中运行的shell脚本。在CI环境中,python调用确定shell高度/宽度返回有趣的值。
我想做点什么:
if (I am running in shell context)
determine height/width of terminal
else
don't
fi
如何在bash脚本中表达这种情况?
答案 0 :(得分:6)
检查标准输入是否为tty设备。
在sh / bash中:
if [ -t 0 ]; then
在Python中:
if os.isatty(sys.stdin):