问题
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