문제

I am running this command in my shell script to get time in milliseconds:

    START=`$(date +%s%N)/1000000`

However I keep getting the error:

   1394661620440271000/1000000: No such file or directory

I tried to change the code by adding brackets, extra dollar signs, but I keep getting different kinds of errors. How can I fix the code? Could anyone help with that?

도움이 되었습니까?

해결책

assuming that you're using bash:

START=$(( $(date '+%s%N') / 1000000 ))

you can't just say / on the command line to divide numbers. (( ... )) does arithmetic evaluation in bash.

다른 팁

I think you want the following:

START=$(($(date +%s%N)/1000000))

You could also use plain string manipulation:

$ start=$(date '+%s%N')
$ echo $start
1394663274979099354
$ echo ${start:0:-6}
1394663274979

The printf statement can round a value to the nearest millisecond:

printf "%0.3f\n" $(date +%s.%N)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top