Tell me more ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm using dash(sh) or bash or zsh. If possible, I would prefer to put in common place.

I want to put proper PS1 settings when I interactive with shell, so these situation should be considered

  1. login (show PS1)
  2. su
  3. sudo
  4. script (Don't show PS1)

I was put PS1 on .bashrc, but it seems not always workable.

share|improve this question
have you executed your code manually , means without bashrc , is it working ?, if possible post your code. – Rahul Patil Jan 18 at 4:01

2 Answers

Each shell has its own escape sequences for PS1, so you need to set it separately for each shell. Furthermore, PS1 only makes sense for interactive shells, it isn't used by other programs. So put PS1 in the interactive startup file for your shell:

  • ~/.bashrc for bash
  • ~/.kshrc for ksh
  • ~/.zshrc for zsh

Bash has a quirk: it doesn't load .bashrc in a login shell, it only loads ~/.bash_profile or absent this ~/.profile. To fix this, put the following lines in your ~/.bash_profike:

if [ -e ~/.profile ]; then . ~/.profile; fi
case $- in *i*) . ~/.bashrc;; esac

For more information about shell setup files, see Alternative to .bashrc.

share|improve this answer

If you want the same prompt for all shells and users, then put it in the /etc/profile file. It is sourced by all shells, and is the standard place for defining PS1.

share|improve this answer
1  
Or in ~/.profile if it is just one user. – Johan Jan 18 at 5:59
@Johan - You are right, but su specifically indicates it's multiple users. – jordanm Jan 18 at 14:39
I still have problem of setting on /etc/profile, 1. how to separtarte different PS1 on different shell. 2. How to check set PS1 in human interactive only. – Daniel YC Lin Jan 19 at 8:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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