How do I ... (NOT a FAQ)

Dan Horsfall ddh at hare.cdc.com
Fri Mar 8 07:35:15 AEST 1991


In article <1991Mar6.164033.8173 at athena.mit.edu>
  mars at athena.mit.edu (Anita Hsiung) writes:
> In article <506 at bria> uunet!bria!mike writes:
> >In an article, mindcraft.com!ronnie (Ronnie Kon) writes:
> >>In article <15710 at mendip.UUCP> mhr at mendip.UUCP (Mark Hull-Richter) writes:
> >>>
> >>>How do I get the current time into my command line prompt?
> >>>
> 
> >The answer is: it depends.  Some shells allow for the execution of embedded
> >commands in a prompt; the Big Three (sh, csh, ksh) do not.
> 
> I use csh and it works for me.  My prompt definition looks like:
> 
>      set prompt="{!} (labs-n) `date +%T`${cwd}% "
> 
> resulting in:
> 
>      {43} (labs-n) 11:36:13 /usr/ahsiung%
> 
> Of course, the time only updates when I "cd".
> 
> -- Anita --

My man pages for csh describe the pre-defined variable "prompt" thusly:

     prompt     The string which is printed before each command
                is read from an interactive terminal input.  If a
                ! appears in the string, it will be replaced by
                the current event number unless a preceding \ is
                given.  The sequence \\ is replaced with a single
                \.  The prompt should only be set by the user if
                it is already defined so that it will not be
                printed when processing shell scripts by using
                the statement

                     if ( $?prompt ) set prompt='\!% '

                If the sequence \@x appears, where x is one of
                the characters listed below, then it will be
                replaced by the current time and date in the
                indicated format.

                     R time as HH:MM AM/PM, e.g. 8:40PM
                     r time as HH:MM:SS AM/PM, e.g. 08:40:25 PM
                     m month of year - 01 to 12
                     d day of month - 01 to 31
                     y last 2 digits of year - 00 to 99
                     D date as mm/dd/yy
                     H hour - 00 to 23
                     M minute - 00 to 59
                     S second - 00 to 59
                     T time as HH:MM:SS
                     j day of year - 001 to 366
                     w day of week - Sunday = 0
                     a abbreviated weekday - Sun to Sat
                     h abbreviated month - Jan to Dec
                     n insert a new-line character
                     t insert a tab character

                The default prompt is %, or # for the super-user.

In this manner, one need not change directories to change the prompt.  
Hope this works for you.

-- 
   Horse
                                       +    Control Data Corporation      
   Dan Horsfall     +1-612-482-4622    +    4201 Lexington Ave North      
   Internet   ddh at dash.udev.cdc.com    +    Arden Hills MN 55126 USA      



More information about the Comp.unix.wizards mailing list