Question

I'm experiencing some problems trying to capture the output of a simple command:

$timeTotal = `echo $timeTotal + $time | bc -l`;

But I'm getting the following errors:

sh: +: not found
sh: Syntax error: "|" unexpected

This command works perfectly in bash but it seems sh is being actually used. At the very beginning I thought that the problem is the pipe usage (although the sum is not well interpreted neither). What confuses me is that the following command in the same script causes no error and works properly:

my $time = `cat $out.$step | bc -l`;

Any suggestions?

Était-ce utile?

La solution

$timeTotal contains a trailing newline it shouldn't, so you're executing

echo XXX

and

+ YYY | bc -l

instead of

echo XXX + YYY | bc -l

You're surely missing a chomp somewhere.

There's also a double-quote in your command that's out of place.

Autres conseils

The backticks are deprecated. Use the qx(..) syntax instead.

$timeTotal = qx(echo $timeTotal + $time | bc -l");
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top