Link to home
Start Free TrialLog in
Avatar of stuntman
stuntman

asked on

Changing Bourne Shell prompt

Hi.. I need, well want... to find a way to change the bourne shell (sh) prompt to display my present working directory instead of it's default prompt... how do I do this??

Thanks in advance!

Robert
ASKER CERTIFIED SOLUTION
Avatar of cgreenup
cgreenup

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of julio011597
julio011597

Hello people,

i'm not a proficient shell programmer at all, so this is less a comment than a question.

I tried to add a new 'test' user and put in his bin dir a custom cd command, looking something like this:

--//--
#!/bin/sh

/usr/bin/cd $*
PS1="`pwd`> "
export PS1
--//--

then put in his .profile this: CDPATH=$HOME/bin
so that issuing 'cd something' would run the custom cd command.

This did not work ("of course" you may say!:)

There's something deeply wrong in this approach, or did i just miss something?

BTW, i agree with cgreenup, as there are other shells available, which are usually much more powerful than sh Bourne shell (and i'm not just talking about setting a custom prompt).

Thanks and rgds, julio
What is happening is the script is starting a new shell, and then executing the body of the script.  Changes made to the environment of the new shell, including PS1, and working directory, are discarded when the new shell exits, leaving you back in your old shell, in your old wd, with your old prompt.

Also, 'export CDPATH=$HOME/bin' wouldn't do exactly what you expect, there.  What you would need to do to execute something in you bin over something else system wide would be 'alias cd=$HOME/bin/cd'.  Or you could set your path up such that $HOME/bin is searched before the other bins.

Last thing, is your cd in /usr/bin/?  Mine's built into the shell. :/

-chrisg@gibson.gibson.com
> What is happening is...

Sure (silly me)!

About 'cd', on my DEC running DU4.0, 'which cd' gives /usr/bin/cd, and i may find a cd command under that directory (a binary executable). So, maybe, your second paragraph does not apply for my OS.

Thanks a lot for your attention (and sorry for the intrusion).

Cheers, julio
Avatar of stuntman

ASKER

I am working on a project that uses the 'sh' shell... and, sadly, I MUST use it!  So, even though the other shells may be easier, it won't help me at this point... sadly...   SO...  anybody???  

sh prompt to be working directory.... It must be dynamic, not of the usual PS1= type....  must change when I change directory...

HELP!!!!!!!!    :)

Thanks

stuntman, I appreciate the points and your vote of confidence (I really do), but you ought to save them until your question is answered in full.  Maybe, if you tell us a little more about the project you're working on, it might help (maybe?).  Plus, if points are still being offered, that's that many more people who will try to answer your question.  Someone else might know exactly what you're looking for.

I won't be offended in the least if you take the points back and resubmit the question.  I don't know how to go about this, but I'm sure someone in customer service can tell us how.

Anyway, if you want to send examples, feel free to email them if you'd rather.

-chrisg@gibson.gibson.com

PS.  julio, email me so we don't keep adding comments to the page :)