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

Re: Bash and the PS1 environment variable [was: grep: show matching line from pattern file]



On 6/2/22 22:50, Will Mengarini wrote:
* David Christensen <dpchrist@holgerdanske.com> [22-06/02=Th 19:18 -0700]:
[...]
Now I can almost match your prompt -- there is a dash before 'bash':

2022-06-02 19:05:10 dpchrist@laalaa ~
$ PS1="\\h/${TTY#/dev/} \\s$SHLVL \\w \\A \$?\\\$"
laalaa/pts/8 -bash1 ~ 19:08 0$

The dash seems to be coming from the '\s' bash(1) -> PROMPTING ->
backslash-escaped special characters:

2022-06-02 19:12:58 dpchrist@laalaa ~
$ PS1="\\s"
-bash

The dash indicates you're running a login shell.  That's useful
information, because a login shell is initialized differently.
See section INVOCATION in `man bash`.

You see in the rendered prompt it says "-bash1"; "1" is $SHLVL.
If you run another bash from inside that bash, and again set PS1
as you did above, you should see "bash2" instead of "-bash1".


RTFM bash(1), I see:

  PROMPTING

\s the name of the shell, the basename of $0 (the portion following the final slash)

  INVOCATION

A login shell is one whose first character of argument zero is a -, or one started with the --login option.


Thank you for the explanation of your PS1 and the subtleties of Bash, variable expansion, remove matching prefix pattern, $0, and PS1 '\s'.


David


Reply to: