Computing.Net > Forums > Unix > Interactive Prompt PS1 with Korn

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Interactive Prompt PS1 with Korn

Reply to Message Icon

Name: doutdes
Date: June 14, 2006 at 06:59:53 Pacific
OS: Tru64 Unix
CPU/Ram: EV4
Product: DS20
Comment:

Hi,

I have been trying to get the PS1 into a personal format, I use Korn shell.
What I am trying is for the PS1 to only show the last two directories.
I got that right, the problem is that once I set the PS1 with it, it keeps showing the first directory.

# pwd
/usr/users/plaj
# pwd | awk -F/ '{x= NF-1 ; if (x >1){ print "/"$x"/"$NF} else {print}}'
/users/plaj
# PS1=`pwd | awk -F/ '{x= NF-1 ; if (x >1){ print "/"$x"/"$NF} else {print}}'`"# "
/users/plaj# cd /
/users/plaj#




Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: June 14, 2006 at 21:34:57 Pacific
Reply:

Sorry, but the PS1 doesn't support the syntax you are using. As you've described, you can set the initial PS1 value with the awk command you've described. The only way that PS1 can change dynamically is to use the internal shell variables. For example, the PWD variable is populated by the results of the cd command. Therefore this command:

export PS1='$PWD'" "

displays the current directory after the cd command completes. Unfortunately, PS1 doesn't allow you to allow external unix commands after the initial setting.

You might find this link interesting:

http://www.itworld.com/Comp/2378/swol-062300-unix101/


0

Response Number 2
Name: doutdes
Date: June 15, 2006 at 13:47:42 Pacific
Reply:

Thanks for the explanation, it pushed me to try the following, but offcourse it didn't work neither, the only other thing I found was trying with putenv(), but that will require to do some C programming and compile it, and I will probably mess more than I want to.
The only thing is that I didn't quite understood why the SECONDS env variable did work for the time part of the script(prompt)

#Including a Time Prompt
export SECONDS="$(date '+3600*%H+60*%M+%S')"
typeset -Z2 _h _m _s
_hh="(SECONDS/3600)%24"
_mm="(SECONDS/60)%60"
_ss="(SECONDS%60)"
_time='${_x[(_m=_mm)==(_h=_hh)==(_s=_ss)]}$_h:$_m:$_s'
#Prompt
export PWD="$(pwd | awk -F/ '{x= NF-1 ; if (x >1){ print "/"$x"/"$NF}}')"
PS1=$_time'${PWD}#'


0

Response Number 3
Name: nails
Date: June 22, 2006 at 09:16:16 Pacific
Reply:

I shared this problem with a friend of mine. While normal unix tools won't work with PWD when setting PS1, ksh patterns will. This seems to work:

export PS1='${PWD#${PWD%/*/*}} >'

However, it breaks if you cd to a subdirector with one or less parents such as tmp or /



0

Response Number 4
Name: doutdes
Date: July 12, 2006 at 14:07:40 Pacific
Reply:

Thanks, all is easier now :D


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


If statement exception BigBrother and Hobbit Ser...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Interactive Prompt PS1 with Korn

File transfer UNIX - dail-up modem www.computing.net/answers/unix/file-transfer-unix-dailup-modem/2097.html

help with korn shell if command www.computing.net/answers/unix/help-with-korn-shell-if-command/4543.html

Solaris 7:Problem with Korn Shell initia www.computing.net/answers/unix/solaris-7problem-with-korn-shell-initia/2037.html