5

When I log in to my server which has dash as default shell, I get a prompt that looks like this:

\[\033[1;31m\]\u\[\033[0m\]@:\w #

How can I configure the server that it shows something like this?

user@hostname!dash!/path/$

And in case, I have to put this in .profile, how can I keep the fancy shell in other shells like bash and zsh?

(On my server .profile is a symlink to .bashrc)

6

Dash is designed to be a minimal shell for fast script execution. Being comfortable for interactive use is very much not a design goal. If you want a fancy prompt, use a shell designed for interactive use: zsh, fish, or at least bash. The escape sequences you show are for bash.

Dash does expand variables in the prompt, so you can set a prompt like this in .profile (and override it in .bashrc, .zshrc, etc.).

: "${USER=$(id -un)}" "${HOSTNAME=$(uname -n)}"
if [ $0 = "-sh" ]; then
  export PS1='$USER@$HOSTNAME!$0!:$PWD/\$ '
fi
  • @rubo77 Dash doesn't have an interactive startup file. You can put export PS1='$USER@$HOSTNAME:$PWD/\$ ' in your .profile. But really, you shouldn't use dash interactively. You'll very quickly run into something else you don't like, such as the lack of command line edition. – Gilles Sep 29 '14 at 23:49
  • sure, but I would like to put "dash" iside the prompt, so everybody gets a hint, that he's on dash – rubo77 Sep 29 '14 at 23:52
  • @rubo77 You can check $0, or detect bash (with BASH_VERSION), ksh (with KSH_VERSION), etc. and consider dash the fallback case. Or you can set a prompt for dash in .profile, and the capable shells will overwrite that setting in their interactive startup file. – Gilles Sep 30 '14 at 0:25
  • you of course could also test in your .profile whether HOSTNAME is set, and if not, set it explicitly to the name of your host (or the output of hostname if you use the same .profile for several machines). – celtschk Sep 30 '14 at 8:05
  • 1
    @Purefan What's dahs? Did you mean dash? It reads .profile if it's invoked as a login shell. That's true on OSX like everywhere else. What does this have to do with this question anyway? If you have a different problem, ask a new question. – Gilles Mar 11 '16 at 14:45

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.