1

首先:不好意思用c shell,怪我公司不怪我。我和你们大多数人现在一样讨厌这该死的东西(起初我想,嘿,这还不错)。

我正在尝试减去从时间戳中获得的大量数字。这是我正在尝试的:

set curTime = `date +%s%N`
#... some stuff
@curTime = `date +%s%N` - $curTime #get the diff
echo "time taken: $curTime"

但是我猜这些数字太大了——在我尝试几秒钟之前它工作得很好。这是我在日志中看到的内容:

@curMilli = 1349996279792995000 - 1349996279170458000
@curMilli: Command not found.

正如我所说,我做了完全相同的事情date +%s并且很好,所以我假设这与数字的庞大有关。

我怎样才能做到这一点?非常感谢。

4

1 回答 1

1

文章http://en.wikipedia.org/wiki/Bc_programming_language有一个简短的部分“在 shell 脚本中使用 bc”。一个测试:

set curTime = `/bin/date +%s%N`
/bin/sleep 2
set prevTime = $curTime
set curTime = `/bin/date +%s%N`
set diff = `echo "$curTime - $prevTime;" | /usr/bin/bc`
echo $diff

20将给出(初始变量后面的数字):

2016204108

Ps:我希望我能投票给你两次"I hate the damn thing as much as most of you do now (at first I was like, hey this ain't so bad)."

于 2012-10-12T15:33:35.273 回答