[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: bash scripting q



Hugo Vanwoerkom wrote:
Hi,

On my way to elapsed time in a bash script, I created the do_chrono command. It pumps the elapsed time to stdout.

So if I do:

a=do_chrono

and then:

$a

I get: 0:3:19.

Problem: I can't use that $a anywhere, e.g. if I say:

echo $a

I would expect to see 0:3:19 again, but I don't, it says

do_chrono


How do I use that $a in command parameters, like logger?


So this is the way it works now:

#!/bin/bash
a=do_chrono # elap to stdout
$($a) &> /dev/null  # Suppress output 1st call clears the chronometer(1)
sleep 1
logger -t do_hibernate_prep =before sleep 4 $($a) # elap since (1)(2)
sleep 4
logger -t do_hibernate_prep =after sleep 4 $($a) # elap since (2)
exit 0

Produces:

Sep 29 09:21:27 debian do_hibernate_prep: =do_hibernate_prep before sleep 4 0:0:1.30 Sep 29 09:21:31 debian do_hibernate_prep: =do_hibernate_prep after sleep 4 0:0:4.30

There probably are better ways of doing it.
Thanks for the answers, couldn't find that in the guide...
H























Reply to: