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!

seeing the directory you are in without having to type pwd 1

Status
Not open for further replies.

Chrissirhc

Programmer
May 20, 2000
926
GB
Hi,

In my shell I see $ as the directory. How do I change my environment so that I can see the directory I am actually in, without having to type pwd?

I am using korn shell.

Thanks in advance,

Chris
 
You can display various info with PS1
Put this in your .profile ( or just execute it )
export PS1='$USER'" on "`hostname`": "'$PWD'" > "

HTH

Dickie Bird (:)-)))
 
Cheers Dickie Bird,

So how would I just have the path?

Thanks,

Chris
 
You have to redefine the cd built-in function in your ENV file like this:
Code:
cd() {
  command cd "$@" > /dev/null
  PS1="$(pwd -P)> "
}

Hope This Help
PH.
 
Well that figures...

I had to change is slightly. I thought I was using ksh but the system actually starts as csh then I change.

Anyway I changed it slightly to
setenv PS1='$HOSTNAME'": "'$PWD'" > "

But I get this annoying equals sign on my prompt. How do I get rid of that???

Also why is there a .profile.mine a .cshrc and a .envfile on my home space? Are they all different kinds of things?

Thanks,

Chris
 
Anyway:
man csh
man ksh

Hope This Help
PH.
 
If you want to use the Korn shell, why not change it in /etc/passwd so you use the Korn shell from the beginning, rather than logging in with csh and then going to ksh?

The .profile.mine looks like someone saved out the .profile to another file before changing .profile. I doubt it does anything, unless it's being called from some other file. The .cshrc is an environment file for the C shell. the .envfile may be called from one of the other files (.cshrc or .profile, for example).

I use ksh on Sun and this is what I have in my environment file, which is defined in my .profile (ENV=$HOME/.kshrc; export ENV):

export HOST=`/usr/bin/uname -n`
export LOGNAME=`/usr/bin/logname`
export PS1='$LOGNAME@$HOST: $PWD > '

And this is what my prompt looks like:

root@myserver: /export/home >

I don't have to redefine the cd function.




 
bi,
and what is your prompt when you change your working directory with cd ?
 
It's the directory I'm in. If I type cd /tmp, the prompt looks like this:

root@myserver: /tmp >

The $PWD works for ksh on Sun, HP, and AIX.
 
bi,
OK. I didn't realize that the PS1 var was evaluated before each prompt. So, you'll be starized :)

Hope This Help
PH.
 
Bi

Having > on the end of you PS can cause problems itself.
see the problem PeterEy had in AIX Forum

thread52-641737





--
| Mike Nixon
| Unix Admin
|
----------------------------
 
I can't get this to work.

I have added the line (ENV=$HOME/.kshrc; export ENV) (no colon) to my .profile. I'm using /bin/ksh as my shell, and I have

export PS1="`hostname`:$PWD> "

in my .kshrc file.

Couple of questions,

Why set up the ENV variable in a separate shell?
and
Why can't I get it to work?
 
I'm not terribly familiar with ksh, but you should be able to find the equivalent commands for my csh custom prompt. I have this in my .cshrc file:

alias setprompt 'set prompt="\cwd: ${cwd}\% "'
alias cd 'chdir \!* && setprompt'

The prompt it gives me is

cwd: /home/user
%

with the path changing wherever I go. I've found that having the cwd on a separate line from the prompt keeps things clean when I'm nested deeply in the file system. :) When the shell starts up, just type

% setprompt

and the custom prompt will appear. It's not fancy, but it does what's needed with very little effort on your part.
 
mrmac228,

I don't know why this isn't working for you. I added the line you are using (which is different from what I posted) and I still get the prompt I would expect (myserver:/export/home/me).

Do a set | grep HOME and make sure the .kshrc is in the directory that you see.

As for why in a separate file? I don't know. "That's the way we've always done it."

 
mrmac228,
> I have added the line (ENV=$HOME/.kshrc; export ENV) (no colon) to my .profile
If your export instruction is enclosed in (), then it's executed in a subshell and has no effect for your login shell.

Hope This Help
PH.
 
Oops. Sorry. That was a misunderstanding because of the way I typed it. No. don't put it in parentheses. I meant that as an aside.
 
Within Linux I use the following:

I add the following to the end of /etc/bashrc



if [ $(whoami) = root ]
then
PROMPT_COMMAND='echo -en ^[[01\;05\;31\;40m ; echo -n $(/etc/fancyprompt) ;
echo ^[[00m'
else
PROMPT_COMMAND='echo -en ^[[01\;33\;40m ; echo -n $(/etc/fancyprompt) ; echo
^[[00m'
fi


and /etc/fancyprompt contains the following


echo -n "HOST="
echo -n `hostname`
echo -n " : USER="
echo -n `whoami`
echo -n " : CWD="
echo -n `pwd`


This gives me a prompt that shows the system name, the current user and the current directory. In addition if I am logged in as root then the prompt changes to flashing red to warn me that I have root powers.

Cheers - Gavin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top