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

Re: How does Squeeze initialize PS1 ?



Paul E Condon <pecondon@mesanetworks.net> writes:
> I'm debugging some bash scripts and reading the scripts that come as
> part of Squeeze installation. I find several places where there are
> statements the set a value from variable PS1, BUT all of them seem
> to be in scripts that only get executed if PS1 is already non-empty.
> i.e. they are after a statement 
> [ -z "$PS1" ] && return
> which, I think, executes return if PS1 is empty.

That's true. The commands

$ apt-get source bash
$ grep -r '"PS1"' .

show that it is bash itself that sets PS1 if it is interactive:

  /* set up the prompts. */
  if (interactive_shell)
    {
#if defined (PROMPT_STRING_DECODE)
      set_if_not ("PS1", primary_prompt);
#else
      if (current_user.uid == -1)
        get_current_user_info ();
      set_if_not ("PS1", current_user.euid == 0 ? "# " : primary_prompt);
#endif
      set_if_not ("PS2", secondary_prompt);
    }
  set_if_not ("PS4", "+ ");


> 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'. 

That is not true. If I run "bash foo.sh" then I am not running shell
interactively. Instead, the shell is interpreting commands from a file
in a completely automated fashion and not consulting me before each
command.

However, "bash foo.sh" can very well have stdin and stdout connected
to a terminal. Having a terminal and being interactive are two
different concepts.


Reply to: