• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3759
  • Last Modified:

How to modify login prompt to show current working directory for c shell.

I am using Red Hat Linux ES4.0 update 5. I need to modify the login prompt for a non-root user so that it displays the current working directory all the time. The users default shell is csh and cannot be changed to bash. The users home directory contains .cshrc file.
0
aspnetdev
Asked:
aspnetdev
  • 8
  • 7
  • 3
  • +1
2 Solutions
 
ozoCommented:
set prompt=%/
0
 
omarfaridCommented:
Hi,

Add something like the line below to your .login or .cshrc in your home dir:

alias cd 'cd \!*; set prompt="$user@`uname -n`:$PWD >> "'

For ksh / bash, you may add to your .profile / .profile_bash in your home dir:

PS1="$LOGNAME@`uname -n`:\$PWD >> "
0
 
TintinCommented:
For bash, it's easier to do

export PS1='\u@\h:\w >>'
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
ozoCommented:
and to similarly include the username and host in csh
set prompt='%n@%m:%~ >>'
0
 
aspnetdevAuthor Commented:
Both solutions are correct, I would like to know if there is a way to display the full path to the current working directory.
0
 
aspnetdevAuthor Commented:
The solutions provided by ozo and omarfarid are correct. Since I am not using bash Tintins solution will not apply even though it may be right for bash shell. I am waiting to see if we can display the full path to the current directory.

Thanks to everyone.
0
 
omarfaridCommented:
This is what my solution gives :)
0
 
omarfaridCommented:
The solution given by ozo does not change the prompt when you change dir !
0
 
aspnetdevAuthor Commented:
Actually I think I made a mistake, the solution provided by ozo is working but provides the current working directory not the full path to the current working directory. The solution provided by omarfarid does not work! sorry ! I did not check it thoroughly.
The .cshrc file seems to ignore [alias cd 'cd \!*; set prompt="$user@`uname -n`:$PWD >> "'] and goes to the next line which is
#set prompt = \[`id -nu`@`hostname -s`\%/]\#\

It always takes this even though I commented it out.
0
 
omarfaridCommented:
Please test it from command prompt first, then add it to .login file. Do not add both solutions since you will not be able to tell which one is working and which one is not.

Which system are you working on? and are you testing with csh or tcsh?
0
 
aspnetdevAuthor Commented:
I don't have a .login file. I am using RHEL4.0, and csh.
0
 
omarfaridCommented:
You need to create it in your home dir.

What do you get from the csh command prompt when you create the alias?
0
 
omarfaridCommented:
Please note that .login in home dir will be run when you login and your login shell is csh.

.csh in your home dir will run each time you call csh (including login time).

What is your login shell? (can be seen in the /etc/passwd file or by running echo $SHELL)
0
 
aspnetdevAuthor Commented:
login shell is csh.
0
 
omarfaridCommented:
Thank you :)

Any problem in running the command from csh command prompt?
0
 
ozoCommented:
what are you seeing as the difference between "the current working directory" and "the full path to the current working directory"?
0
 
aspnetdevAuthor Commented:
Hello ozo and omarfarid:

Ozo's solution works perfectly for non root users who have the default shell as csh. However it does not work for the root user. I now found that the root users shell is bash. It has a .bashrc and .cshrc in its home directory. Tintin's solution works at the login shell, I am not sure why it does not work when I put it in .cshrc or .bashrc file for the root user.
0
 
omarfaridCommented:
Hi aspnetdev,

If you notice, I provided you with ways to set the prompt for csh and bash, etc.

I have been asking you if you faced any problem in the provided solution and till now no answer.

If you don't want me to continue replying to your question you may kindly say so.

0
 
aspnetdevAuthor Commented:
Ok

I used tintin's solution for the root user who is using bash shell and ozo' solution for non root user. This has solved my problem. I am thankful to omarfarid also but for the sake of fairness will divide the points between Tintin and ozo.
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 8
  • 7
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now