[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bug in the Bash Reference Manual

From: John Lange
Subject: Bug in the Bash Reference Manual
Date: Thu, 30 Jul 2009 10:19:53 -0500
User-agent: Internet Messaging Program (IMP) H3 (4.1.3)

In section "6.3.2 Is this Shell Interactive?", the Bash Manual advocates:

if [ -z "$PS1" ]; then
  echo This shell is not interactive

however, this does not work in any shell I've tested (RedHat 4 & 5, OpenSUSE 11.1, SLES 10 & 11). It seems that the idea of testing the prompt variable was taken from section 5.5 of the (now) historical Unix F.A.Q. originally written in 1992.

In current Bash implementations, the "PS" variables are not set when invoking bash scripts interactively (I believe they are only set for login shells). Try this mini-script:

set | grep PS

Even without the "#!/bin/bash", it still returns the same result.

However, "man bash" has a different idea, the "-t fd" test as in:

if [[ -t 0 ]] ; then
  echo interactive

Good except that interactive scripts aren't always attached to a terminal. Sometimes they are attached to a socket. So:

if [[ -t 0 || -S /dev/stdin ]] ; then
  echo interactive

Of course, just because stdin in bound to a socket doesn't prove that it's interactive since you could invoke it remotely with cron but presumably the author of the script would be aware of it's intended use.

John Lange

This message was sent using IMP, the Internet Messaging Program.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]