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
Syntax error with DATEPART in Calculated field - MS SQL REporting Services
Can't add foreign key in mySQL
RAID Controller policy on Dell 2950-III PERC 6/i
Drivers Compaq Presario SR5060AN devices
SMTP Auth command syntax
iPhoto - physically keep photos on firewire drive?
I can connect with VPN client but can not ping or connect to any clients on the inside.
How to turn off high security
Tape Backup Performance
Get client's computer specification from browser