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

Re: How does Squeeze initialize PS1 ?



Quoting Paul E Condon on 2010-08-20 17:36:32, in Message-Id
<[🔎] 20100820223632.GB2190@big.lan.gnu>

> i.e. they are after a statement [ -z "$PS1" ] && return which, I
> think, executes return if PS1 is empty.
ACK.

> The comment just before the above line of code is: "# If not running
> interactively, don't do anything" For me, the implication of this
> comment is that a non-empty PS1 IS the defining characteristic of
> 'running interactively', but I would have thought 'interactive' should
> be characterized by having a tty attached to sysin and sysout for
> communication to a 'user'.
s/sys/std/ as a matter of pedantry.

[ -n $PS1 ] isn't what _defines_ a shell as being interactive. That's
merely one test to determine if the shell's interactive or not. Another
test would be to see if the value of $- contains 'i'. From bash(1):

       An interactive shell is one  started  without  non-option
       arguments and without the -c option whose standard  input
       and error are both connected to terminals (as  determined
       by isatty(3)), or one started with the -i option. PS1  is
       set and $- includes i if bash is interactive, allowing  a
       shell script or  a  startup  file  to  test  this  state.

> I can imagine that a non-empty PS1 is used as an indicator, in which
Yes, it is used as an indicator, as stated above.

> case whatever code that actually sets up the tty also sets PS1 to some
> minimal non-empty value like a single space or a dot, but is this
> actually the way it works, and where is it?
It's actually the shell that sets $PS1 on startup. I don't have the bash
source (or 1003.2 if it's defined there) on hand as I'm composing this
offline, so I leave finding exactly where and how an exercise to the
reader.

While technically you CAN set PS1=' ', or even unset PS1, I wouldn't
recommend it. The smallest I'd recommend setting it to is '\W:\$ ', or
'\$ ' (note the trailing spaces). The former displays just the last
component of your current directory, and the latter doesn't even display
that, just a $ (or # if you're root)

I further recommend against unsetting PS1 as without some kind of prompt
you have little visual indication your current process is finished. A
demonstration:

bryans@esterhazy:~ OLDPS1=$PS1
bryans@esterhazy:~ unset PS1
find ~ -name "`apgwrap`" && echo done # [1] [2]
done

[1] apgwrap is the following:

#!/bin/sh
apg -a0 -n1 -m10 -x12 -MNCL -tc $(dd if=/dev/urandom bs=16 count=1 2>/dev/null)

[2] the 'echo done' is there only to show when the process is finished.
Without it I'd likely have sat waiting for quite a while.

> Where can I read about these issues?
See bash(1), or the info document for it if you have it installed.

> Puzzled.
Hope this explanation helps.

-- 
 _  Brian Ryans 8B2A 54C4 E275 8CFD 8A7D 5D0B 0AD0 B014 C112 13D0     .
( ) ICQ UIN: 43190205 | Mail/MSN/Jabber: BrianLRyans@gmail.com       ..:
 X  ASCII Ribbon Campaign Against HTML mail and v-cards: asciiribbon.org
/ \ "The most powerful optimization tool . . . may be the Delete key."
							 -- Eric Raymond

Attachment: signature.asc
Description: Digital signature


Reply to: