3

When I log into a server running SunOS 5.10, my prompt initially is "-bash-3.2$"

Then when I run the following commands, I can see that the prompt is slightly different after typing bash (it no longer begins with a dash), yet echo $SHELL gives the same result.

-bash-3.2$ echo $SHELL
/bin/bash
-bash-3.2$ bash
bash-3.2$ echo $SHELL
/bin/bash

What does this mean, and what implications does it have?

3
  • What is the output of 'echo $PS1' ?
    – schaiba
    Commented Jan 27, 2013 at 20:43
  • What are the contents of /etc/profile, /etc/bashrc, ~/.bashrc and ~./bash_profile. Also, as glenn already pointed the difference between login and nonlogin shells, can you try running bash --login?
    – njsg
    Commented Jan 27, 2013 at 20:59
  • Try echo $0 instead of echo $SHELL Commented Jan 27, 2013 at 21:07

2 Answers 2

4

PS1 default value under bash is \s-\v\$

  • \s is replaced by the name of your shell ($0)
  • \v is the bash version

The leading - is just due to the first shell being a login shell. This dash is used to differentiate login shells from other ones. The second shell is not a login shell so hasn't that prefix.

PS1 stays like this in your case because none of the scripts sourced at startup override it.

There is no implication about these prompts.

By the way, this OS is more commonly referred to as "Solaris 10" than "SunOS 5.10".

4
  • Heh, fun thing is that uname will actuall show SunOS rather than Sparc, even if /etc/*release has OpenSolaris :-)
    – njsg
    Commented Jan 27, 2013 at 21:13
  • @njsg SunOS rather than SPARC ???
    – jlliagre
    Commented Jan 27, 2013 at 21:14
  • s/Sparc/Solaris/. Sigh.
    – njsg
    Commented Jan 27, 2013 at 21:20
  • 1
    @njsg That's the expected behavior. In your case SunOS 5.11 is the kernel while (Open)Solaris is the whole OS. Just like say Linux 2.6.32-46 is a kernel and Debian 6.0.6 is a distribution using it.
    – jlliagre
    Commented Jan 27, 2013 at 21:25
1

The bash manual explains it in the Invoking Bash section:

A login shell is one whose first character of argument zero is ‘-’, or one invoked with the --login option.

Login shells invoke different startup files.

4
  • Yes, this may be what causes the behaviour, but without actually asking the OP for the content of these init files or to start bash with --login, you can't really say this is an answer.
    – njsg
    Commented Jan 27, 2013 at 20:58
  • @njsg What Glen is saying is that login(1m) starts a login shell by prepending its argv[0] with a "-". That's the standard way to start a login shell (--login is not). That explains why the name of the shell as reported by PS1 starts with "-". Commented Jan 27, 2013 at 22:59
  • Yeah, maybe he should include the part where he explains how that affects a shell with these values of PS1 that were listed above.
    – njsg
    Commented Jan 27, 2013 at 23:05
  • I couldn't find any reference in my ubuntu login(1) man page. Commented Jan 27, 2013 at 23:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .