simple SH variable

Greetz all,
I'm using OBSD 2.9 with /bin/sh as my shell. I want to modify the SH prompt to reflect my current working directory.
I'm new to shell programming, so pardon if I'm going about things wrong :wink:
I thought I'd be able to do it with the following line:

PS1="`pwd`# "

but of course, that leaves the prompt as my home directory when I log in and remains so even when I change directories. Can someone point me to the right way to have my SH prompt update the CWD everytime I CD into a new one?

sorry for the quirkiness, but I should revise this question.

How does one set the prompt to read as follows?

<username>@<hostname>:<current_working_directory>#

for instance,

user@host:/user$

I would also allow the shell to show a hash (#) when root is logged in and a $ when a regular user logs in.

I thought I had it figured out before, but I didn't.

Hi,

Hope this would help you.

Try to set the PS1 in ~/.shrc or you can type it (not automatic).

-----------------------

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

-----------------------

should be working, and it will show you (for example):

-----------------------

 sh-2.05\# PS1=$'\\\\u@\\\\h:\\\\w\\\\$ '

 root@negative:~\# cd data

 root@negative:~/data\#   

-----------------------

no go.
when I enter that in (actually in my .profile file in ~), the prompt comes out reading:

\u@\h:\w$

not correct, of course.

What I have entered in the variable as follows:

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

and also exacltly as you had shown in your reply.
Is it possible it's a different systax for Bourne used under OpenBSD?

Im using OpenBSD and i put a "nice" Prompt:
----
PS1='\[\e[1;30m\][\[\e[0;35m\]\t\[\e[1;30m\]]\[\e[1;36m\]\u\[\e[1;30m\]@\[\e[0;36m\]\h\[\e[1;30m\]:\[\e[0;37m\]\w\[\e[1;30m\]\$\[\e[0;37m\] '
----

just for not getting bored with BLACK & WHITE prompt :slight_smile:

eh.. I have to ask, which shell are you using? I am using /bin/sh and even copying the variable as you set it ( PS1='\[\e[1;30m\][\[\e[0;35m\]\t\[\e[1;30m\]]\[\e[1;36m\]\u\[\e[1;30m\]@\[\e[0;36m\]\h\[\e[1;30m\]:\[\e[0;37m\]\w\[\e[1;30m\]\$\[0;37m\]' )
only makes my command... exactly that.
can someone refer a tutorial that goes over this?

I'm using /bin/bash, but i believe it works in /bin/sh too,

Bash has different built-in escapes, some of which are especially for prompts. In bash, you can get a list of them from the man page... have you check the man page for sh on your system? (Note: some systems with bash installed will simply have a symbolic link from /bin/sh to /bin/bash)

For adding the hash to the prompt of root users, you might be able to do something like this with your /etc/profile :

PS1="whatever you want"
if [ ! "`id -u`" = "0" ]; then
      PS1="${PS1} # "
else
      PS1="${PS1} $ "
fi

Hope that helps a little...

Here's the URL related with this purpose.
+ http://www.mcsr.olemiss.edu/unixhelp/environment/env8.html
+ http://www.utexas.edu/cc/faqs/unix/Shell-prompt.html
+ http://rtl.netfilter.se:81/skijk/prompt/
and they are Googled.

Peace,

ah yes. Thanks for the info and links; this should give me enough to work with for now.
Peace.