Microsoft
Software
Hardware
Network
Question : Test for interactive vs non-interactive shell
I am trying to incorporate a test into my bash scripts which will select different code depending on whether or not it runs in an interactive or a non-interactive mode.
Given the following two programs:
File: qk.sh
---------------
#!/bin/bash
plen=${#PS1}
if [ -z "$PS1" ]; then
echo -e "This shell is interactive:$plen :$PS1"
else
echo -e "This shell is non-interactive:$plen :$PS1"
fi
File2: qk2.sh
-------------
#!/bin/bash
./qk.sh > ckit
cat ./ckit
When I run qk.sh during and interactive session, it prints
"This shell is interactive:0 : "
When I run qk2.sh, which I assume means I am running qk.sh non-interactively, I get the same output.
Any insights would be appreciated.
-G
if [ -z "$PS1" ]; then
echo This shell is not interactive
else
echo This shell is interactive
fi
Answer : Test for interactive vs non-interactive shell
if perl -e 'exit -t STDOUT' ; then
echo -e "This shell is non-interactive:$plen :$PS1"
else
echo -e "This shell is interactive:$plen :$PS1"
fi
Random Solutions
Ruby string manipulation, easy enough?
Unable to open default email folders. Outlook 2003 install after MS office 2007 trial removal
Exchange Server Crashed - 500 Points, Inbound e-mails not coming through.
DELETE ALL MAIL IN A USERS INBOX THROUGH EXCHANGE, POSSIBLE?
Button Script not loading swf
Writing a bash script to write output to a file
Updating the gecos field on /etc/passwd file on different servers from a text file with the users an field information.
Exchange: "...delivery was refused..."
reducing pagefile.sys
Where is the .ost file location configured in Outlook Connector 12?