- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Show date and time at shell prompt
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2006 11:07 PM
тАО04-06-2006 11:07 PM
===========================
export DATE="$(date '+%d%b')"
export SECONDS="$(date '+3600*%H+60*%M+%S')"
typeset -Z2 _h; typeset -Z2 _m ; typeset -Z2 _s # 2 digits, zero padded
# hours, minutes and seconds...
_hh="(SECONDS/3600)%24"
_mm="(SECONDS/60)%60"
_ss="(SECONDS)%60"
_time='${_x[(_m=_mm)==(_h=_hh)==(_s=_ss)]}$_h:$_m:$_s'
export PS1=$(echo "${DATE}${_time} `whoami`@`hostname`
\$PWD
# ")
======================================
It works fine in sh
07Apr18:53:48 root@sa27
/
# ps
PID TTY TIME COMMAND
22757 pts/1 0:00 ps
6257 pts/1 0:00 sh
However, when i change to ksh, it doesnt work anymore.
07Apr19:00:30 root@sa27
/
# ksh
07Apr${_x[(_m=_mm)==(_h=_hh)==(_s=_ss)]}$_h:$_m:$_s root@umwsa27
$PWD
#
Anyone can show where the problem is?
Thanks.
Nash
Solved! Go to Solution.
- Tags:
- PS1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2006 11:11 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-07-2006 01:02 AM
тАО04-07-2006 01:02 AM
Re: Show date and time at shell prompt
The use of SECONDS as a variable to which you make assignments is not sane. Have a look at the 'sh-poxix' and/or 'ksh' manpages. In particular: "Each time this parameter is referenced, the number of seconds since shell invocation is returned. If this parameter is assigned a value, the value returned upon reference is the value that was assigned plus the number of seconds since the assignment." Should you "insist" on using that name, at least 'unset' SECONDS beforehand.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-16-2006 02:41 PM
тАО04-16-2006 02:41 PM
Re: Show date and time at shell prompt
Nash
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-23-2008 10:55 PM
тАО10-23-2008 10:55 PM
Re: Show date and time at shell prompt
The problem of dealing the unset variables is solved by
set +u
But it is not necessary because shell supports some facilities in parameter substitution to deal the unset variables:
set -u
echo ">>${A}<<"
ksh: A: parameter not set
echo ">>${A:-}<<" # prints nothing
>><<
Therefore, if you change the line where variable _time is initalize as suggested:
_time='${_x[(_m=_mm)==(_h=_hh)==(_s=_ss)]:-}$_h:$_m:$_s'
then you won't be concerned with the setting 'set +u'