- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Current date & time in posix 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
Forums
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
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
тАО10-10-2006 09:02 AM
тАО10-10-2006 09:02 AM
Every time I set it, I get the time in the prompt, but it does not change.
I want the time to be dynamic and reflect the current time when the command prompt is displayed.
Any ideas???
Solved! Go to Solution.
- Tags:
- PS1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-10-2006 09:26 AM
тАО10-10-2006 09:26 AM
Re: Current date & time in posix shell prompt
you must escape date command in PS1 to be run every time, when PS1 is displayed:
export PS1=`hostname`" ""\$(date )"#
cheers,
ivan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-10-2006 09:38 AM
тАО10-10-2006 09:38 AM
Re: Current date & time in posix shell prompt
With the PS1 string:
PS1=`hostname`" ""\$(date)"#
This is what I get:
saturn $(date)#
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-10-2006 10:11 AM
тАО10-10-2006 10:11 AM
Re: Current date & time in posix shell prompt
ivan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-10-2006 07:49 PM
тАО10-10-2006 07:49 PM
Solutionmodify your ~/.profile to include:
ENV=~/.shrc
export ENV
then edit/create your ~/.shrc to include:
export DATE="$(date '+%d%b')"
export SECONDS="$(date '+3600*%H+60*%M+%S')"
typeset -Z2 _h; typeset -Z2 _m ; typeset -Z2 _s
_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} # ")
set +u
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-11-2006 01:44 AM
тАО10-11-2006 01:44 AM
Re: Current date & time in posix shell prompt
That's some script.
Work's great!
As I try to dissect it to understand exactly what is going on here, I can't seem to understand why the 'export SECONDS=' line produce a dynamic variable that changes every time you reference it.
I tried the date command with a (less complicated) formatted output string, and it produced a static output not changing until the variable is explicitly set again.
Why is this different?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-11-2006 01:50 AM
тАО10-11-2006 01:50 AM
Re: Current date & time in posix shell prompt
a quick search of the archive brought the solution:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1017839
Its the re-evaluation of time that makes the difference to just using `date`.
Script just needed a bit of adjusting.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-11-2006 01:56 AM
тАО10-11-2006 01:56 AM
Re: Current date & time in posix shell prompt
David Totsch explained the logic of this solution in this thread:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=38457&admit=-682735245+1160574500123+28353475
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-11-2006 02:10 AM
тАО10-11-2006 02:10 AM
Re: Current date & time in posix shell prompt
I live for these things, my boss thinks it's a waste of time to obsess over these geek things, but this will give me some food for thought to distract me the rest of the day.
Thanks!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-11-2006 04:40 AM
тАО10-11-2006 04:40 AM
Re: Current date & time in posix shell prompt
export PS1=$(echo "${DATE}${_time}")' @ $PWD #'
Thanks for the lession in obscure shell inner workings.