Solved

Changing Bourne Shell prompt

Posted on 1997-06-04
6
1,362 Views
Last Modified: 2010-05-18
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
0
Comment
Question by:stuntman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 1

Accepted Solution

by:
cgreenup earned 50 total points
ID: 2006375
I don't think that you can set the bourne shell (sh) prompt to display the current working directory.  You can change the prompt by doing something like this:

export PS1='my prompt $ '

which will make your prompt look like:

my prompt $

which of course isn't much better.  It's backslash-escaped
characters (or formatting sequences) that put the working directory in the prompt, and the bourne shell ignores them for the prompt.

What I suggest is not using the bourne shell (sh) for an interactive shell.  You could use bash, tcsh, zsh, ksh, or another, instead.  With each of these, you have very powerful prompt-setting capabilities.  For example, if you used bash, you could do this:

export PS1='\u@\h:\w\$ '

which would set your prompt to look like:

user@host:/working/directory$

Or with tcsh:

set prompt="%n@%m:%~%% "

which would do the same thing, tcsh style.  With tcsh, you can even put codes in your prompt for boldface, underline, and standout mode.

Try one of these other shells for your interactive shell.

One other thing of note:  Are you sure you're using sh?  When I invoke sh on my machine, it actually starts bash.  Might be different for you, but it's worth looking into.

Keep me posted.

-chris@gibson.gibson.com
0
 
LVL 5

Expert Comment

by:julio011597
ID: 2006376
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
0
 
LVL 1

Expert Comment

by:cgreenup
ID: 2006377
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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:julio011597
ID: 2006378
> 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
0
 

Author Comment

by:stuntman
ID: 2006379
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

0
 
LVL 1

Expert Comment

by:cgreenup
ID: 2006380
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 :)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Unix / Linux grid computing 5 169
reinstall 1 92
OpenLDAP Proxy to Active Directy 6 453
add some character at the end of line in vi 7 107
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question