HP9000-L Archives

February 2006

HP9000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Lal Samuel Varghese <[log in to unmask]>
Reply To:
Lal Samuel Varghese <[log in to unmask]>
Date:
Wed, 1 Feb 2006 18:11:14 +0530
Content-Type:
text/plain
Parts/Attachments:
text/plain (44 lines)
Tracy Pierce wrote:

>touch mylog
>ts=<as above>
>doit='echo "$($ts) " >> mylog ; echo "$mycommand" >> mylog ; $mycommand
>  
>
>>>mylog'
>>>      
>>>
>mycommand='do this'
>$doit
>mycommand='do that'
>$doit
>mycommand='do more'
>
>...thereby logging both the command and its result to mylog without
>trying to maintain two copies of the command in the script.  I'm missing
>something re the behavior of quoting, but can't see past the trees.  is
>there a user-friendly (read idiot-friendly) reference?
>  
>
What you need is the 'eval' command. This command evaluates its 
arguments just as if they were input to shell.

So it should be:

touch mylog
ts="date '+%Y%m%d %H%M%S'"
doit='(eval $ts; echo $mycommand; eval $mycommand) >> mylog'

mycommand="do this"
eval $doit
mycommand="do that"
eval $doit
mycommand="do more"
eval $doit

Note that 'eval' is used in all the three places where a command is 
stored in a variable. Hope this helps.

Regards,
Lal

ATOM RSS1 RSS2