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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ksh prompt and environment variables

Status
Not open for further replies.

Zteev

Programmer
Jul 28, 2003
17
US
Hi everybody,

I added this line into my user's .profile :
export PS1='$PWD $'

If I su to root, I won't have the # sign instead of the $. Am I missing something.

Also, I've setup an alias in my .profile :
alias ll="ls -la"

But again, if I su to root, that alias won't be available.

Is there any way I could setup 'system-wide' aliases?

Thank you very much!

Zteev
 
I'm not sure what you're asking about the prompt problem. When you su to root, how are you doing it? Do you just type:
su root

or do you type
su - root

And what are you seeing?

To make aliases available to everyone, add the alias to /etc/profile.

 
I type su root (not su - root). With bash you can get this to work and I remember that it is possible with ksh but it was a long time ago and now I'm totally confused about it.

I thought /etc/profile was a linux-only file. Could you tell me whats the difference between /etc/environment and /etc/profile ? They seem to do the same thing?

Thanks a lot for your answer :)

Zteev
 
Quick note :

I added this line to /etc/profile :

alias ll="ls -al"

When I su to root (su root) ll isn't available. :-(

Any ideas anyone?

Thank you very much!
 
/etc/environment gets sourced only at boot time.

/etc/profile and $HOME/.profile files only get executed at LOGIN time. They set your LOGIN profile.

You need to add your alias to /etc/kshrc, for all korn shell users OR $HOME/.kshrc for individual users. These files get sourced each time you open a new shell.

 
/etc/kshrc don't exist on my server by default, so I've created one and added my alias but when su'ing to root the alias isn't available. Like /etc/kshrc isn't read. :-|

Thanks for the explanations.

Zteev
 
The reason you are not getting your vars displayed is becuase you are just issuing su (username)

this doesn't run any profiles , keeps the same environment that you logged in as , but if you do su - root , this will
execute the users profile. The /etc/profile is global but if one exists in users home directory then that gets run

HTH
 
If you don't use the - when you su, you keep the environment you had before you did the su. The .profile of the user you su'ing to isn't read, so even if you put the alias in that user's .profile, or in a .kshrc which is called from the .profile, you still won't have the alias. (The only time I will not use the - when I su is when I have cd'd into a long path and all I need is root's permissions, but none of the rest of root's environment. And then I get out of root quickly.)

Try su - root and see if the alias is available.

/etc/profile is in HP-UX, AIX, Sun Solaris and probably all the other flavors of Unix.

If the shell you are using is Bash, perhaps Bash doesn't use /etc/profile?



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top