我的shell脚本如何才能确定它是否是一个真正的外壳或没有? [英] How can my shell script determine whether it's in a real shell or not?

查看:109
本文介绍了我的shell脚本如何才能确定它是否是一个真正的外壳或没有?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的个人终端,并在CI环境中运行shell脚本。在CI环境中,蟒蛇呼吁确定外壳的高度/宽度返回搞笑值。

I have a shell script that runs in my personal terminal and in a CI environment. In the CI environment, the python calls for determining shell height/width return funny values.

我想做些事情的效果:

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

我怎么能前preSS这种情况下,在bash脚本?

How can I express this condition, in a bash script?

推荐答案

检查标准输入是一个tty设备。

Check if standard input is a tty device.

在SH / bash的:

In sh/bash:

if [ -t 0 ]; then

在Python的:

if os.isatty(sys.stdin):

这篇关于我的shell脚本如何才能确定它是否是一个真正的外壳或没有?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆