Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


Closed Thread
  Search this Thread
Old 10-29-2004, 03:40 PM   #1
LQ Newbie
Registered: Mar 2004
Posts: 7

Rep: Reputation: 0
custom cd command

I use redhat 9. The console I'm running in by default uses bash.

I've edited my prompt by altering the .bashrc file at using the PS1 line say:

PS1="<MyName><\w> \!# "

My prompt looks like this:

<MyName><~> 6001#

That is basically my name and then the directory I'm in with respect to my home directory (uXXXXXX).

Here comes what I'm trying to change. I'm happy with my prompt but in bash (atleast the default one my RedHat 9 had) the cd command will print the working directory on the next line after you hit enter. So "cd MyStuff" will look somethin like this:

<MyName><~> 6001# cd MyStuff
<MyName><~/MyStuff> 6002#

As you can see here, the print working directory that the cd command does is redundant. I've been told that bash does not do print working directory after a cd. And that seems to be true for some cases (logged in remotely to a system using SSH). But under RedHat 9 it seems to do this for you. It's not aliased so that's not the problem, maybe aliasing it is the answer but I wouldn't know how to do that for cd. Any help would be great on information on how I can get cd to not pwd.
Old 10-29-2004, 11:57 PM   #2
Registered: Jan 2002
Location: Corvallis
Distribution: Slackware 10.0
Posts: 48

Rep: Reputation: 15
If you want to try aliasing it, and you're sure you're using bash, do the following:

For all users, edit /etc/profile and add
alias cd='cd'

If you want it aliased for only the current user, edit /home/<i>username</i>/.bashrc
alias cd='cd'

Or if you're root, edit /root/.bashrc with the same thing.

I've never seen this happen with RH9, but I haven't used RH for a long time. You might check /etc/profile to make sure its not aliased there.

Old 10-30-2004, 01:19 AM   #3
LQ Newbie
Registered: Jul 2001
Posts: 19

Rep: Reputation: 0
I dont use RH but I do use bash... wouldnt have thought there would be much difference.

I know that you can make the prompt return on a newline with \n. The only way I could sorta replicate your shell prompt is with:

PS1="\w\n<MyName><\w> \!# "

But I doubt that was the problem...

If you echo $PS1 what do you get?
As your user?
As root?
Does it still do it if you change your prompt with this command: PS1="\u:\w> "

What does your ~/.bashrc and ~/.bash_profile look like?

I guess I am mostly just curious... because if it still does the same thing after you have changed it with the new PS1 above then I am stumped unless there is something in your ~/.bashrc and ~/.bash_profile that is causing this..
Old 11-01-2004, 03:00 PM   #4
LQ Newbie
Registered: Mar 2004
Posts: 7

Original Poster
Rep: Reputation: 0
I didn't figure it out but my university unix guru taught me how, and It works through aliasing. If you want your cd command to be silent you add this alias to your .bashrc/.bash_profile:

alias cd="cd $1 < /dev/null"

you are basically redirecting the standard output of the cd command away from the screen and into oblivion. Its nifty and its a good thing to learn.

Plus now my command prompt is really intuitive and unclutered.
Here is a snippit of it working.

<MyName><~> 4096# cd c_work
<MyName><~/c_work> 4097# cd~
<MyName><~> 4098# cd..
<MyName></home/bobcat/students> 4099#

Very nice stuff. this experiance has given me some reason to look more into shell scripting.
Old 11-01-2004, 07:39 PM   #5
LQ Guru
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 245Reputation: 245Reputation: 245
Please do not post the same thread or discussion in more than one forum. Picking the most relevant forum and posting it once there makes it easier for other members to help you and keeps the discussion all in one place.

Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Usermin Custom Command help please AlphaNate Linux - Software 0 09-12-2005 08:16 AM
Custom Command? - Excuting Program SilverX Slackware 11 09-20-2004 03:49 PM
How to make a custom linux command? m3kgt Linux - General 1 03-11-2004 01:23 PM
debian - custom startup command =X= Linux - Distributions 8 04-28-2003 03:38 PM
FREE Coloured custom command prompts!!!!! =) Hegemon Linux - General 8 01-20-2003 04:34 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:45 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration