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
Detecting Proxy Settings
Flash Expanding Menu
Dynamically Loading Body Data in JavaScript
Ghost - VERY VERY SLOW on Intel S5000VSA RAID Configuration.
Exchange Server 2003 Enterprise will not uninstall
Login GPO timeout Event ID 1217
move Officescan server to new server w/o reconfigure
How to order this sequence of events
Folders cannot be opened
Flash game only works correctly after refreshing the page