PS1 and $-, a footnote; was Re: .profile not being src'd at login on uptodate buster
- To: debian-user@lists.debian.org
- Subject: PS1 and $-, a footnote; was Re: .profile not being src'd at login on uptodate buster
- From: David Wright <deblis@lionunicorn.co.uk>
- Date: Wed, 26 Jan 2022 22:59:28 -0600
- Message-id: <[🔎] 20220127045928.GE4844@axis.corp>
- Reply-to: debian-user@lists.debian.org
- In-reply-to: <YHRmuSolpr9DGjrZ@wooledge.org>
- References: <CAD8GWstyK6ojxTYSW8Dd8ma4CbtDEZguMxEidf5ec7KzFTOiFg@mail.gmail.com> <20210410182121.GC13959@axis.corp> <YHH61ahu5TWuRumv@wooledge.org> <20210411141146.GB4614@axis.corp> <YHMKm4+eC1xCBF8N@wooledge.org> <20210412151819.GA3759@axis.corp> <YHRmuSolpr9DGjrZ@wooledge.org>
On Mon 12 Apr 2021 at 11:26:49 (-0400), Greg Wooledge wrote:
> On Mon, Apr 12, 2021 at 10:18:19AM -0500, David Wright wrote:
> > I'm not using PS1 to test whether stdout is a terminal, but whether
> > the file is running interactively. From man bash:
> >
> > "PS1 is set and $- includes i if bash is interactive, allowing a
> > shell script or a startup file to test this state.
>
> The second half of that sentence is referring to the $- part. That's
> what you're supposed to test to see whether the shell is interactive.
>
> # bash
> if [[ $- = *i* ]]; then
> echo "I am an interactive shell"
> echo
>
> # sh
> case $- in
> *i*) echo "I am an interactive shell" ;;
> esac
I happened to come across one place where I might have originally
found the construction I no longer use, and that's in man lesspipe,
very near the end, where it says:
if [ -z "$PS1" ]; then
Cheers,
David.
Reply to: