How can my shell script determine whether it's in a real shell or not?

两盒软妹~` 提交于 2019-12-22 08:08:32

问题


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.

I would like to do something to the effect of:

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

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


回答1:


Check if standard input is a tty device.

In sh/bash:

if [ -t 0 ]; then

In Python:

if os.isatty(sys.stdin):


来源:https://stackoverflow.com/questions/5488180/how-can-my-shell-script-determine-whether-its-in-a-real-shell-or-not

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!