On one of my servers, the prompt is [user@host path]...and I can actually push "tab" to auto-fill the path.

But on my new Ubuntu server, it is just a dollar sign?

migrated from stackoverflow.com Nov 10 '09 at 9:48

This question came from our site for professional and enthusiast programmers.

  • 1
    You can always type pwd to print the name of the current working directory. And are you saying that Tab-completion is not working either? (On some machines I use, I get that short prompt only if I login as root, and I happily leave that in place as a nice warning. As one seldom, if ever, needs to login as root: you're not using root, are you?) – Arjan Nov 10 '09 at 10:27
  • Alex can you tell us what distro you are using? – invert Nov 10 '09 at 10:53
  • I am using Ubuntu. – Alex Nov 10 '09 at 11:08
  • The latest Ubuntu? And are you saying that Tab-completion is not working either? – Arjan Nov 10 '09 at 11:20
  • You seem to be asking two questions: why doesn't tab auto-fill the path, and why is the prompt just a dollar sign instead of [user@host path]. It's a little difficult to vote for answers since none answers both. – Joseph Holsten Nov 10 '09 at 14:01

Since you are asking two questions, I'll answer both.

Why doesn't tab autocomplete file paths?

Because you shell either doesn't support it, or tab completion isn't turned on.

To resolve this, you first need to discover what your shell is. On the machine whose shell you enjoy, run

echo $SHELL

You may see the common /bin/bash, or something less common like /bin/tcsh, /bin/zsh or something else entirely.

Now, you can change your shell on Ubuntu machine. On that machine, first make sure that the shell you want exists. Since the shell might not be in the same location on the Ubuntu machine as on the other, check the location by typing

 which bash

This will give you the path of the shell you want, something like /bin/bash, /usr/bin/bash, or /usr/local/bin/bash. Of course, if you want a shell other than bash, you'll say which tcsh, which zsh, or similar.

If you don't see a path, but instead see bash not found, then you'll need to install the appropriate package, and again use which to find out where the shell was installed.

With the path of your chosen shell, you can finally change your shell by running

chsh -s /bin/bash

replacing /bin/bash with whatever the appropriate path for your shell of choice is.

Why is the prompt a dollar sign instead of [user@host path]?

Because of your prompt environment variables $PS1, $PS2, and so on. These things don't tend to be portable between shells, so here's a few links for likely candidates:

bash has an extensive manual, with pages on Bash Variables (including PS1, &c) and Printing a Prompt (which describes PROMPT_COMMAND, the long name for PS1). Add the following line to your ~/.bashrc

export PS1='[\u@\h \w] '

tcsh has an online manual (just its man page), with a section on the prompt environment variables. Add the following line to your ~/.tcshrc

set prompt='[%n@%m %~] '

zsh has a user guide, with a simple guide to prompts, as well as a manual, with a very detailed reference on Prompt Expansion. Add the following line to your ~/.zshrc

export PS1='[%n@%m %~] '

Bash is not the only shell.

Your issue could be a simple matter of not having a .profile or .bashrc that sets PS1, or it could be that your login shell is not bash at all.

Bash uses gnu readline for things like tab completion. This is a complicated subject and readline even has its own per-user config file.

See man bash, man sh, and man 3 readline. Bash responds to --version. On many linux systems, /bin/sh is not actually bash, but usually a crippled version of ash.

  • 1
    not dash instead of ash? i thought i read something like this – knittl Nov 10 '09 at 11:45
  • 2
    +1 for not having a .profile or .bashrc - unless Alex initially set up his account when he installed Ubuntu, then by default, new users don't have a .bashrc / don't have PS1 set. – Cory Plastek Nov 10 '09 at 14:37

i guess, you are not using bash, but sh and your prompt is not set properly (if this is even possible with sh).

you can get your current shell by typing: echo $SHELL

if you want to start bash, just type bash

  • You can set the prompt with other shells. There is no shell called sh. Echoing $SHELL will print an environment variable called SHELL. This environment variable simply points to the shell, and is only set by bash. It is approximately useless in determining which shell is running, as it only indicates, weakly, that some parent of the current process may have been bash. – DigitalRoss Nov 10 '09 at 9:52
  • well, the program name of shell is sh (in /bin/sh). and yes, echo $SHELL will print the variable SHELL which is usually set. – knittl Nov 10 '09 at 9:55
  • Every unix systems has an executable called /bin/sh, yes. But I know of no shell whose name is sh. I can think of ash, ksh, csh, bash, zsh, and tcsh. The first one is the usual /bin/sh on linux and NetBSD, the last is the usual FreeBSD shell, and the others are optional shells. Many desktop environments change the users login shell to bash while leaving /bin/sh as ash. – DigitalRoss Nov 10 '09 at 10:01
  • 2
    @DigitalRoss sh is the Bourne shell. en.wikipedia.org/wiki/Bourne_shell Some systems (Solaris) still come with a version of Bourne shell that is not just a copy of one of the re-implementations (ash, dash, bash, ksh, zsh). – Chris Johnsen Nov 10 '09 at 10:23
  • ... and bash is known as the "Bourne again shell", which inherited some features from Bourne shell, csh and ksh. – invert Nov 10 '09 at 10:50

You need to set a variable called PS1 on one of your login script, for example /etc/profile or ~/.bashrc. It will depend on your distribution.

Example: http://www.cyberciti.biz/tips/howto-linux-unix-bash-shell-setup-prompt.html

  • not necessarily .bashrc since he might use a different shell than bash – knittl Nov 10 '09 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.