The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Getting current work directory in Command Prompt MeganP UNIX for Dummies Questions & Answers 3 07-20-2007 02:49 PM
Adding # minutes to current time... gptavares UNIX for Advanced & Expert Users 7 06-25-2007 04:10 PM
Setting the current path in the command prompt in (t)csh reborg Answers to Frequently Asked Questions 0 10-10-2006 04:02 PM
Substituting variable with current time jhansrod Shell Programming and Scripting 4 11-20-2005 08:20 PM
current directory as part of the csh prompt jamesloh Shell Programming and Scripting 3 08-28-2002 02:38 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-28-2005
m223464 m223464 is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 41
Help setting PS1 prompt to include current time

Hi,

I'm using the ksh shell and I'd like to set my PS1 prompt on an AIX system to include, amongst ther things, the current time.

This was my best effort: export PS1=$(date -u +%R)'${ME}:${PWD}# '
but this only sets the time to the value when PS1 is defined and the time value doesn't actually change after that.

Any one got any ideas how to achieve this? I've tried searching the forum but can't find anything.

Thanks

Gareth
  #2 (permalink)  
Old 11-28-2005
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,762
PWD, RANDOM and some other environment variables are defined by the shell to point to a function. I don't know of a function defined as a shell symbol that returns date & time.

In the korn shell try:
Code:
PS1='$RANDOM'
Then press return five or six times. There has to be code behind the call to the environment variable becuase it is dynamic.
  #3 (permalink)  
Old 11-28-2005
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
Try quoting the whole string: export PS1='$(date -u +%R) ${ME}:${PWD}# '
  #4 (permalink)  
Old 11-29-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,119
Ygor's solution will work with ksh95 or pdksh. But ksh88 only expands variables...it won't do a general parse. I am not real fond of invoking the date command with each each display of the prompt.

ksh95 has a feature called discipline functions and these can be used to create dynamic variables that work like RANDOM.

Here is a solution that will work with all three versions of ksh. If we set SECONDS, it will continue to advance. So if we set it to the number of seconds since midnight it will serve as a time-of-day clock. To get from seconds-after-midnight to hours:minutes:seconds we need to do some arithmetic. If we reference a imaginary array, we can compute a subscript for it and use side effects from the subscript computation to set other variables. A single date process is used to initialize the clock, but after that the time is computed by the shell itself.

unset _h _m _s
eval $(date "+_h=%H ;_m=%M ;_s=%S")
((SECONDS = 3600*${_h#0}+60*${_m#0}+${_s#0}))
typeset -Z2 _h _m _s
_tsub="(_m=(SECONDS/60%60)) == (_h=(SECONDS/3600%24)) + (_s=(SECONDS%60))"
_timehm='${_x[_tsub]}$_h:${_m}'
_timehms='${_x[_tsub]}$_h:$_m:${_s}'

PS1="$_timehm $ "
  #5 (permalink)  
Old 02-03-2009
gio001 gio001 is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 70
Hello,
just a 'stupid' question I am using an older ksh (ksh88) and from there I enter into tcsh .... where should I place this code (and how should it be re-written, too), if I want to have it create env variables .... maybe by including it in .cshrc or some other startup files (.login or other)?
Well all that I was thinking of doing was to be able to have these env vars available by the time one of the alias statement inside my .cshrc executes, in such a way I could use the env var contents and place it onto the title bar of my xterm window. Result being I should then get a clock displayed in the title bar.
Do you have any advice or ideas?
Thanks for all!
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:38 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0