Andres Jaan Tack
Andres Jaan Tack

Reputation: 23014

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

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?

Upvotes: 4

Views: 830

Answers (1)

grawity_u1686
grawity_u1686

Reputation: 16122

Check if standard input is a tty device.

In sh/bash:

if [ -t 0 ]; then

In Python:

if os.isatty(sys.stdin):

Upvotes: 6

Related Questions