How can I convert this simple python code to Shell script?
import time
import sys
cur_time = int(time.time()*1000)
print cur_time
sys.exit(1)
It's just multiplying the seconds since epoch by 1000 (with some added nanosecond precision).
You can do:
$(($(date '+%s') * 1000))
With the nanosecond precision, inzsh:
$(($(date '+%s.%N') * 1000))
Precision to 2 decimal points, in zsh:
printf '%.2f\n' $(($(date '+%s.%N') * 1000))
As bash (and other shells) does not support floating point arithmetic, you can use bc instead.
Example:
% echo $(($(date '+%s') * 1000))
1462194433000
% echo $(($(date '+%s.%N') * 1000))
1462194596950.2983
% printf '%.2f\n' $(($(date '+%s.%N') * 1000))
1462194696479.11