Operating System - HP-UX
1830044 Members
5488 Online
109998 Solutions
New Discussion

ksh88, hpterm, dynamic PS1 troubles

 
IMTheNachoMan
New Member

ksh88, hpterm, dynamic PS1 troubles

I have searched around the forums and I have not been able to figure out what is wrong.

I cannot figure out how to get my PS1 variable to have dynamic information. I know I have to use ' instead of "" but when I use ' $(...) does not work.

I tried this and it didn't work: http://forums11.itrc.hp.com/service/forums/parseCurl.do?CURL=%2Fcm%2FQuestionAnswer%2F1%2C%2C0xa0ead211e18ad5118ff10090279cd0f9%2C00.html&admit=109447626+1287181133657+28353475

When I use ' shell variables like $PWD work and update but I can't get the current time in there. And I'm also trying to put in a new line with "\n" but that doesn't work either.

Any ideas anyone?





168: @ $: Version 11/16/88

168: @ $: uname -a | sed "s/$HOSTNAME//g"
HP-UX B.11.11 U 9000/800 3367818464 unlimited-user license

169: @ $: typeset -RZ2 _x1 _x2 _x3

170: @ $: let SECONDS=$(date '+3600*%H+60*%M+%S')

171: @ $: _s='(_x1=(SECONDS/3600)%24)==(_x2=(SECONDS/60)%60)==(_x3=SECONDS%60)'

172: @ $: TIME='"${_d[_s]}$_x1:$_x2:$_x3"'

173: @ $: export PS1=${TIME}
"${_d[_s]}$_x1:$_x2:$_x3"
8 REPLIES 8
James R. Ferguson
Acclaimed Contributor

Re: ksh88, hpterm, dynamic PS1 troubles

Hi:

First, Robin's code post was mangled during a Forum update years ago. The '[' and ']' are left and right square brackets, respectively.

typeset -RZ2 _x1 _x2 _x3
let SECONDS=$(date '+3600*%H+60*%M+%S')
_s='(_x1=(SECONDS/3600)%24)==(_x2=(SECONDS/60)%60)==(_x3=SECONDS%60)'
TIME='"${_d[_s]}$_x1:$_x2:$_x3"'
export PS1=${TIME}

Second, if I recall correctly, the post shown only works for the Korn shell. The '$(...)' notation is a POSIX standard that may not apply.

Regards!

...JRF...
IMTheNachoMan
New Member

Re: ksh88, hpterm, dynamic PS1 troubles

Thanks, but that still does not work.

$ typeset -RZ2 _x1 _x2 _x3
$
$ let SECONDS=$(date '+3600*%H+60*%M+%S')
$
$ _s='(_x1=(SECONDS/3600)%24)==(_x2=(SECONDS/60)%60)==(_x3=SECONDS%60)'
$
$ TIME='"${_d[_s]}$_x1:$_x2:$_x3"'
$
$ export PS1=${TIME}
"${_d[_s]}$_x1:$_x2:$_x3"


So is there anyway to do $(...) in KSH88 on an HP-UX box?
Dennis Handly
Acclaimed Contributor

Re: ksh88, hpterm, dynamic PS1 troubles

>So is there anyway to do $(...) in KSH88 on an HP-UX box?

ksh is a real shell, $() works perfectly fine.
Bill Hassell
Honored Contributor

Re: ksh88, hpterm, dynamic PS1 troubles

> So is there anyway to do $(...) in KSH88 on an HP-UX box?

Sure:

export PS1="$(date +"%I:%M:%S %p")
$ "

\n is not available when evaluating the PS1 contents. If you need a newline, include it in the definition like the above example. Be sure you look at the intermediate results before you assign it to PS1.

> export PS1=${TIME}

This will simply assign the current value of the variable $TIME. It will not execute any of the TIME=... instructions.


Bill Hassell, sysadmin
IMTheNachoMan
New Member

Re: ksh88, hpterm, dynamic PS1 troubles

@Bill: I was told that by using double quotes variables are not automatically updated and to use single quotes instead. So what you wrote will work but wont update. And $(..) does not seem to get evaluated in single quotes.
Patrick Wallek
Honored Contributor

Re: ksh88, hpterm, dynamic PS1 troubles

This just worked for me:

export PS1='$(date +"%I:%M:%S %p")
$ '

Bill Hassell
Honored Contributor

Re: ksh88, hpterm, dynamic PS1 troubles

> And $(..) does not seem to get evaluated in single quotes.

You are right of course. Single quotes will return the current contents of variables:

PS1='$SECONDS $'

However, the shell will not process $(..) or `...` or update a static variable. However, the example you mentioned takes advantage of the shell's expansion of integers, specifically when the integer contains the name of a variable. Here's a reference that you were probably using:

http://software.itags.org/bsd/46709/

Following the example, I was not able to get ksh (ksh-1988) to work (PS1 just had the _time expression) but dtksh (ksh-1993 found at /usr/dt/bin/dtksh) returns a static value. Looks like a fair amount of troubleshooting will be needed.


Bill Hassell, sysadmin
Bill Hassell
Honored Contributor

Re: ksh88, hpterm, dynamic PS1 troubles

@Patrick: This worked for me:
export PS1='$(date +"%I:%M:%S %p")
$ '

I tried this on 11.00 through 11.31, POSIX sh, ksh (ksh-1988) and dtksh (ksh-1993), but it only worked with dtksh (ksh-1993). Looks like $(...) may have been enhanced in ksh93 for PS1 expansion.


Bill Hassell, sysadmin