Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 10-28-2004, 01:00 PM   #1
LQ Newbie
Registered: Mar 2004
Posts: 7

Rep: Reputation: 0
altering cd command, can it be done?

This may be more of a unix question, but I'll give it a go anyway. I'm using linux boxes running RedHat 9. the shell - Konsole in RedHat uses bash, knowing this is important.. My goal is to change the command prompt to look alot cooler than I thought the regular one did. I've acheived this:

<MyName><~> 5566#

through changing my .bashrc file at PS1= to say this:

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

\w being current working directory.

This would have been enough, however there is the problem of using the cd (change directory) command. The problem being every time you change directory it prints the working directory. Why is this a problem, because the current directory is already being printed, I really don't need it printed twice. My question is now, can I somehow change the cd command to not print the working directory? Thanks in advance for responses

Last edited by glingon; 10-29-2004 at 07:48 AM.
Old 10-28-2004, 01:09 PM   #2
LQ Guru
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 270Reputation: 270Reputation: 270
That's not a problem with your cd command nor can it be fixed, as it has no idea what type of PS? type input you've customized for yourself. I don't know an easy way around this but it sounds like this would still be a hack for your PS1 environment setting for your user.
Old 10-28-2004, 01:11 PM   #3
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
kshell? you mean ksh? ksh doesn't use bash... they are both shells, they don't use each other. and cd in bash doesn't print the current directory.
Old 10-28-2004, 01:18 PM   #4
Senior Member
Registered: Feb 2003
Location: N'rn WI -- USA
Distribution: Kubuntu 8.04, ClarkConnect 4
Posts: 1,142

Rep: Reputation: 47
If you comment out the PS1= line in your .bashrc, and re-login, does it still print the pwd?

I can only think it is something else that is doing it. Do you have an alias for cd? Do you have a script named cd somewhere in a directory in your path?
Old 10-28-2004, 02:23 PM   #5
LQ Addict
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
Perhaps a thorough read of the bashprompt howto would give you ideas of how to customize the prompt.
Old 10-29-2004, 07:47 AM   #6
LQ Newbie
Registered: Mar 2004
Posts: 7

Original Poster
Rep: Reputation: 0
Still need help

Sorry about the thing about Kshell, i was just looking at the window title Shell - Konsole and thats what came out. I've overviewed the bashprompt howto and it doesn't look like it's going to help me.

My main question here is with the cd command. I've still not found a way to alter this so that it doesn't print the working directory on the next line after you type the command. Someone posted that cd does not do this, but I'm sitting here right now changing directories and its printing the working directory after I use cd.

Any direction would be great.
Old 10-29-2004, 08:11 AM   #7
Registered: Nov 2000
Location: Hermon, ME
Distribution: slackware
Posts: 201

Rep: Reputation: 30
type 'alias' at the command line and see if cd has an alias that is doing this. Some distros will do this to make them more user friendly. Like some will have 'rm' alias as 'rm -i' so that it always asks if your sure you want to delete the file.
Old 10-29-2004, 09:29 AM   #8
LQ Newbie
Registered: Mar 2004
Posts: 7

Original Poster
Rep: Reputation: 0
Nope, cd itself does not have an alias, however... that may be the solution to my problem, could anyone help me with creating and alias for the cd command that does not pwd?
Old 11-01-2004, 03:04 PM   #9
LQ Newbie
Registered: Mar 2004
Posts: 7

Original Poster
Rep: Reputation: 0
Alright, not that you guys don't know any >8 ) . But i went and asked my university unix guru and he gave me the answer. You have to alias the cd command. you use this:

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

there... its useful.
Old 11-24-2004, 08:47 PM   #10
LQ Newbie
Registered: Nov 2004
Location: Kwajalein, RMI
Distribution: Fedora, Red Hat Enterprise
Posts: 1

Rep: Reputation: 0
On Fedora, bash has trouble with alias cd="cd $1 < /bin/null". It can't perform the cd.

On csh or tcsh shells, on SGI unix, the command:
alias cd 'chdir \!* && set prompt="`hostname -s`:${LOGNAME}:`dirs`>'

works to give a prompt like Compter2:JJ:/home>

The prompt can be edited to give any combination of information the user wants to see. The ability to do this is facilitated by having the synonym for cd (chdir) in the builtin commands for the shell. This allows overloading the cd command. In bash, that is harder to do. cd does not normally print the directory again. You may have an overriding alias or two happening.

Hope this helps.


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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Altering cursor size dogpatch Programming 4 12-02-2005 01:57 AM
Altering system messages in Slackware 10.1 DPhusion Linux - Newbie 1 10-27-2005 01:39 PM
altering .iso's adam_boz Linux - General 9 11-05-2002 10:35 PM
altering lilo on floppy boot bluecadet Linux - General 7 10-26-2001 09:11 PM
altering the time at the command line vendemmian Linux - General 1 05-01-2001 06:44 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:00 AM.

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
Open Source Consulting | Domain Registration