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)
3 Answers 3
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
You can test scrptine.I think it can help you.
Comments
You can change the pemission
chmod +x file
and add in the first line
#!/usr/bin/env python
If I am correct it's used to call without the preceding language. The script then calls the language's interpreter to run the code inside the script