mars@athena.mit.edu (Anita Hsiung) (03/07/91)
In article <506@bria> uunet!bria!mike writes: >In an article, mindcraft.com!ronnie (Ronnie Kon) writes: >>In article <15710@mendip.UUCP> mhr@mendip.UUCP (Mark Hull-Richter) writes: >>> >>>How do I get the current time into my command line prompt? >>> >> The construct `command` (note the use of accent grave (`) instead >>of apostrophe (') inserts the result of the command into the command line. (stuff deleted) >If you happened to read the question, the original poster was NOT asking how >to insert the date into the command line -- he was asking how to insert the >date in the 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 --
ddh@hare.cdc.com (Dan Horsfall) (03/08/91)
In article <1991Mar6.164033.8173@athena.mit.edu> mars@athena.mit.edu (Anita Hsiung) writes: > In article <506@bria> uunet!bria!mike writes: > >In an article, mindcraft.com!ronnie (Ronnie Kon) writes: > >>In article <15710@mendip.UUCP> mhr@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@dash.udev.cdc.com + Arden Hills MN 55126 USA
pechner@ddtg.com (Michael Pechner) (04/18/91)
In article <506@bria> uunet!bria!mike writes: >In an article, mindcraft.com!ronnie (Ronnie Kon) writes: >>In article <15710@mendip.UUCP> mhr@mendip.UUCP (Mark Hull-Richter) writes: >>> >>>How do I get the current time into my command line prompt? >>> >> The construct `command` (note the use of accent grave (`) instead >>of apostrophe (') inserts the result of the command into the command line. >>(Refer to the man page for your shell for a more complete explanation). I >>believe this facility is present in Bourne shell; I know it is in C and Korn >>shells. > >If you happened to read the question, the original poster was NOT asking how >to insert the date into the command line -- he was asking how to insert the >date in the 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. > >-- In ksh I have a function to put in your .kshrc file that will insert time, or other if you want. Most ksh people know about this one. unalias cd function _cd { cd $@ ; PS1=`date '+%H:%M '``hostname`".""$LOGNAME"" ""$PWD"">" export PS1 } alias cd='_cd' My prompt prints "hh:mm mikey.pechner /whatewver/idunno>" -- pechner@mikey.ddtg.com (Michael Pechner) | Pizza Probably The Worlds Most DuPont Design Technologies Group | Perfect Food. Santa Clara, Ca | Carbo, Meat, Dairy, And Veggie | All Food Groups In One.