Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

customise prompt - sh, ksh, bash

Status
Not open for further replies.

dbase77

Technical User
Apr 23, 2002
591
IE
hi,

quick question about solaris shells. How do i customise unix shell for sh, ksh, bash? For example i want my prompt like "username@machinename path >" . the path will change every time i change my path.

thank you in advance.

regards,
feroz
 
This should work in ksh and bash. Put the following 2 lines in your .profile
Code:
PS1='$LOGNAME@'`uname -n`' $PWD >'
export PS1
Greg.
 
Hi,

what about in sh shell. I'm having problem to set the prompt for it. anybody could give me a hand, please?

thank you.

regards,
feroz
 
In the bourne shell (sh) there is no environment variable that holds the current working directory. I don't think you can do what you want in bourne shell.
 
You could try this in the .profile :

_cd() {
cd $*
PS1="${PWD} >"
}
alias cd=_cd
cd .

or better, put this in .kshrc the add this to .profile :

ENV=${HOME}.kshrc ; export ENV

The difference is that .profile is executed when you log on, and .kshrc when you call a shell, so this way you don't lose the PS1 variable when you start a new shell.
hoope it helps.
Mike
 
I like that idea Mike, but unfortunately the alias command doesn't work in sh. Also, $PWD env variable is not maintained in bourne shell, so you would need a line in your function like:

PWD=`pwd`

Is there an equivalent to alias in the bourne shell?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top