Operating System - HP-UX
1836355 Members
2284 Online
110100 Solutions
New Discussion

Re: PS1 that reflect the current time

 
S.C. Fun
Advisor

PS1 that reflect the current time

We can use PS1="$PWD>" to reflect the current directory at prompt. But we definitely can't use PS1="$(date)>" to always reflect the current time and date. What should be the proper way?
5 REPLIES 5
Marcin Wicinski
Trusted Contributor

Re: PS1 that reflect the current time

Hi,

Try this:

PS1=`date` " >"


later,
Marcin Wicinski
S.C. Fun
Advisor

Re: PS1 that reflect the current time

If I've not mistaken, `date` gives you the same result with $(date) . All I want is a prompt that keep updating the date and time whenever a carriage-return is performed.

For e.g.:
Fri Aug 10 17:03:31 SST 2001>
Fri Aug 10 17:06:24 SST 2001>
Fri Aug 10 17:07:00 SST 2001>
Robin Wakefield
Honored Contributor

Re: PS1 that reflect the current time

Hi,

This will give you the time:

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}

Rgds, Robin.
Bill McNAMARA_1
Honored Contributor

Re: PS1 that reflect the current time

Hey Robin,
will the time be dynamically updated on the PS1?
I used to have a script for a zsh on old dec alphas that dynamically showed time, however when a platform upgrade occured the script no longer worked and I forgot about it since then.

Later,
Bill
It works for me (tm)
Robin Wakefield
Honored Contributor

Re: PS1 that reflect the current time

Hi Bill,

Yes, ksh only. No way can I can't take credit for it, but it is quite neat isn't it.

Rgds, Robin