4

I was in the middle of installing updates for Ubuntu when I came across an error, which allowed me to "Start a new shell to examine the situation". Doing so placed me at the top of my directory structure in the same window but appending # to the end.

What does the # represent?

How is this change achieved from the command line?

6
  • You mean that the prompt ends with # instead of $? Oct 31, 2018 at 2:30
  • 1
    You need to give us a lot more information than this. For example, what updates were you installing (was it a few packages or was it going from one OS version to another) and what was the error that you encountered. Also, I presume you want to know how to fix your system and not how to change the prompt? (BTW, thanks for teaching me the word "octothrope" First time in years of using it that I've seen it called that!)
    – Ray
    Oct 31, 2018 at 2:53
  • @Ray the questions are clearly not about fixing anything. What does the octothorpe represent and how is it achieved is pretty clear. Oct 31, 2018 at 2:59
  • Also this: askubuntu.com/q/881998/295286 Basically there's very elaborate ~/.bashrc for each user on debian based systems, which sets the prompt. The leading / means you're in top most aka root directory Oct 31, 2018 at 3:03
  • @ChaiT.Rex I don't know about "pretty clear". I mean, the question does ask what # means. Yes. So the first sentence about an error is irrelevant? Then, at the very least, the question should contain a phrase indicating that the OP "doesn't care" about the error.
    – Ray
    Oct 31, 2018 at 3:44

1 Answer 1

6

It sounds like you were given a root shell. A root shell is typically indicated with a hash sign (#) as opposed to a user shell which is usually indicated with a dollar sign ($).

Whether or not there is a directory name or user name as well depends on the particular shell in use, as a root shell could look like any of the following:

#
/#
/dir#
username:/dir#
username@hostname:/dir#

The last of the above examples is the default prompt in Bash in Ubuntu. The first is the default in the dash shell. Try it with /bin/sh. Of course this is configurable in both.

To open a root shell, the shortcut is:

sudo -i

This opens the root user's configured shell as a login shell, which will usually be bash. It's a shortcut to sudo su -. If you want to open a different shell as root, without modifying the root user's configured shell, you can use the long-winded:

sudo su -s /bin/sh -

Replace /bin/sh with the shell you want to open.

5
  • This answers the first part of my question "What does this represent" thank you. If you could answer "how this is achieved" I'll accept this as the answer.
    – Struan
    Oct 31, 2018 at 11:54
  • @StruanMurray this happens when you start a root shell, eg sudo -i. You could also set your PS1 to use # instead of $, but I wouldn't recommend it. However, I don't know how Bash changes the prompt to # when the shell is owned by root. I don't know where to find it in the source code, I can't find it in the Bash manual, I can't find any variable that does it, and I can't find any Stack Exchange question that explains it. So, if that is what you want to know, great question! If you edit your question accordingly I will vote to reopen it - if you don't want to, I might ask it myself.
    – Zanna
    Oct 31, 2018 at 12:50
  • @Zanna Thanks for this, it wasn't exectly how the character was changed in the source code which I wanted to know, though that may be down to my poor question-wording, but you are right in that it may be a really good question to know where those variables are stored or whether they are hard-coded into the bash prompt, feel free to post your own question! You've answered my question with the sudo -i being the "How this is achieved" part of my question, I would accept this as the answer should you post one but understand that the question may be deleted as a similar one has been asked before.
    – Struan
    Oct 31, 2018 at 21:12
  • @StruanMurray Thanks for your comment clarifying what you wanted to know :) thomasrutter may want to edit this answer to include that you can start a root shell with commands such as sudo -i. Your question is unlikely to be deleted as it has a positive score and positively scored answer. "Duplicates" of good quality are not generally deleted - closing them prevents answers being added, but they are considered useful. If you like the idea of the question I suggested, feel free to ask it! I might get round to it some time tomorrow or later in the week, if you haven't done so.
    – Zanna
    Oct 31, 2018 at 21:44
  • Edited my answer accordingly. Dec 11, 2018 at 22:41

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