- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: got time working in shell prompt, but date is ...
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
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
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
06-28-2010 10:51 AM
06-28-2010 10:51 AM
got time working in shell prompt, but date is not
#cat ~/.profile
~sniped~
export DATE="$(date +'%D')"
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'
~sniped~
but the date does not change.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2010 11:00 AM
06-28-2010 11:00 AM
Re: got time working in shell prompt, but date is not
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2010 11:07 AM
06-28-2010 11:07 AM
Re: got time working in shell prompt, but date is not
If you are trying to make the prompt include the date, which I think is a bad idea, set the values you want into the variable PS1
Your snipped code area needs to include perhaps the date command.
variable=$(date)
Do some further processing in the parenthesis, to get the exact data you want.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2010 11:35 AM
06-28-2010 11:35 AM
Re: got time working in shell prompt, but date is not
# cat ~/.profile
# Custom varibles
EDITOR=vi
export EDITOR
stty erase ^?
export HISTFILE=$HOME/.sh_history
export HISTSIZE=5000
export HISTFILE HISTSIZE
alias ls="ls -aF"
export DATE="$(date +'%D')"
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="^[[35m$(echo ${DATE} ${_time}) ^[[32m`whoami`@^[[31m`hostname`^[[36m
\$PWD ^[[0m$(echo "\n# ")"
My prompt look like:
06/26/10 11:32:04 username@host /home/username
#
The date does not change but time does.
Yes, this is very Linux like :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2010 11:36 AM
06-28-2010 11:36 AM
Re: got time working in shell prompt, but date is not
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2010 12:00 AM
06-29-2010 12:00 AM
Re: got time working in shell prompt, but date is not
Because the prompt should only be "$ " and nothing else.
It is the window title bar that should have the machine and directory path.
And you should have one clock on your desktop, not timestamps for each of your shells.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2010 05:07 AM
06-29-2010 05:07 AM
Re: got time working in shell prompt, but date is not
Say what? Most things I agree with you, Dennis, but that is one of the most asinine statements I've ever read.
If he wants the date and time on the prompt, more power to him.
>>It is the window title bar that should have
>>the machine and directory path.
Well, I can't say I agree there either.
Part of the beauty of Unix is you can make it do almost anything you want. I personally prefer the server name and pwd to be in my PS1 prompt.
Everyone is entitled to their own opinion, I just happen to completely disagree with you in this case.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2010 10:32 AM
06-29-2010 10:32 AM
Re: got time working in shell prompt, but date is not
It depends on what you are doing.
If you absolutely positively need to know what machine you are on, I see your point.
But I prefer a minimalist prompt so I can see my commands, especially when command editing.
I found that prompt fanciness gets in the way.
>I just happen to completely disagree with you in this case.
That's fine. :-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2010 10:43 AM
06-29-2010 10:43 AM
Re: got time working in shell prompt, but date is not
I am using escape sequences to add color to my prompt.
Having time it great to compare things such as Service Guard fail overs quickly.
Date is great for taking snap shots of the terminal for later reference.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2010 10:29 PM
06-29-2010 10:29 PM
Re: got time working in shell prompt, but date is not
For instance, what shell are you trying to use?
ksh doesn't seem to do this, so are you using bash by any chance ?
And what version of bash?
The reason it doesn't work, is because you have a very long set of lines to make the time work, but the date is pushed in a single variable and then used in the prompt. You should do something like you did with the time, to make it work.
Or when you use bash you don't have to do it so hard, just do:
PS1='$(date +"%D %H:%M:%S) \$PWD $ '
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2010 11:13 PM
06-29-2010 11:13 PM
Re: got time working in shell prompt, but date is not
hour, minutes, and seconds change in your prompt because the calculation is based on a "live" variable; your shell apparently supports the special variable SECONDS, which is constantly and automatically updated with the number of seconds that the shell has been alive.
In contrast, the DATE output is based on a variable which is set only once and not updated.
Perhaps DATE can be updated by forcing re-evaluation of its arguments, e.g.:
(eval echo $(date +'%D'))
but no guarantee :-)
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2010 11:18 PM
06-29-2010 11:18 PM
Re: got time working in shell prompt, but date is not
Agree.