How do I test within a bash script for the presence of an interactive shell?
The most common answer for this question says either to test the value of $PS1 or test for "i" in the value of $-. However, this isn't working for me in bash even though I'm fairly certain that I've used the $PS1 technique with Korn shell in Solaris.
Is there another way?
Thank you.
--
-- Ghodmode
Give a man a fish and he'll come back to buy more... Teach a man to fish and you're out of business.
The most common answer for this question says either to test the value of $PS1 or test for "i" in the value of $-. However, this isn't working for me in bash even though I'm fairly certain that I've used the $PS1 technique with Korn shell in Solaris.
Code:
vince@home:~/dev/workspace/practice$ echo -e "PS1: $PS1\n\$-: $-\n\nsetup.sh:\n`cat test.sh`"
PS1: ${debian_chroot:+($debian_chroot)}\u@\h:\w\$
$-: himBH
setup.sh:
if [ -z "$PS1" ]
then
echo "NOT INTERACTIVE"
else
echo "INTERACTIVE: \"$PS1\""
fi
case "$-" in
*i*) echo "INTERACTIVE: \"$-\"" ;;
*) echo "NOT INTERACTIVE: \"$i\"" ;;
esac
vince@home:~/dev/workspace/practice$ ./test.sh
NOT INTERACTIVE
NOT INTERACTIVE: ""
Is there another way?
Thank you.
--
-- Ghodmode
Give a man a fish and he'll come back to buy more... Teach a man to fish and you're out of business.