0

I've been looking to a tutorial on how to customize my terminal. When I try to customize the PS1 into something like

PS1="\u@\h \W -> "
export PS1;

After I source the file in the terminal, instead of getting the username@host directory I get

\u@\h \W -> 

What I have so far in my .bash_profile and .bashrc files is:

.bash_profile

if [ -s ~/.bashrc ]; then
    source ~/.bashrc;
fi

.bashrc

PS1="\u@\h \W -> "
export PS1;

Any help would be highly appreciated, thanks!

7
  • play with \ or quotes
    – alecxs
    Jun 11 '20 at 11:01
  • What output do you get for echo $0?
    – muru
    Jun 11 '20 at 11:03
  • @muru in the terminal?
    – Ryk
    Jun 11 '20 at 11:04
  • @Ryk wherever it is that you're seeing \u@\h \W ->
    – muru
    Jun 11 '20 at 11:04
  • The output is -zsh
    – Ryk
    Jun 11 '20 at 11:04
2

What output do you get for echo $0 ?

The output is -zsh

Which seems to mean you're running Zsh, not Bash. Zsh doesn't support Bash's prompt expansions, but has a system of its own. See: http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html

Try to put something like this in .zshrc:

PS1='%n@%M %~ -> '

You could verify which login shell you have by peeking at /etc/passwd, or running getent passwd $USER (should work on Linuxes). The last field is the shell.

If you want to run Bash as your login shell, chsh -s /bin/bash should work to change that.

6
  • it works, thanks. what happens to the bash files (where I put my code firstly)? Do they override or since I use .zsh does the .zshrc have higher priority?
    – Ryk
    Jun 11 '20 at 11:18
  • @Ryk, yeah, that is a bit curious. If your login shell indeed is Zsh, like it looks to be, then it seems odd for the Bash-specific files to be read at all. Since you export PS1 it might perhaps get inherited to your zsh process, but since a non-interactive Bash clears it, that doesn't happen too often. I'm guessing blindly here anyway.
    – ilkkachu
    Jun 11 '20 at 11:21
  • It might be a misguided attempt at "migrating users to zsh" through simply sourcing the user's bash-related files from the corresponding zsh initialization files.
    – Kusalananda
    Jun 11 '20 at 11:26
  • @Kusalananda, yep, that could be one...
    – ilkkachu
    Jun 11 '20 at 11:35
  • @Ryk, you may want to check all your init files, see: zsh.sourceforge.net/Intro/intro_3.html and gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html
    – ilkkachu
    Jun 11 '20 at 11:36

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.