Subject: | |
From: | |
Reply To: | |
Date: | Wed, 1 Feb 2006 18:11:14 +0530 |
Content-Type: | text/plain |
Parts/Attachments: |
|
|
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
|
|
|