[英]Python to Shell Script?
How can I convert this simple python code to Shell script? 如何将这个简单的python代码转换为Shell脚本?
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). 这只是将自纪元以来的秒数乘以1000(具有增加的纳秒精度)。
You can do: 你可以做:
$(($(date '+%s') * 1000))
With the nanosecond precision, in zsh
: 纳秒级精度,在zsh
:
$(($(date '+%s.%N') * 1000))
Precision to 2 decimal points, in zsh
: 精度到2个小数点,以zsh
:
printf '%.2f\n' $(($(date '+%s.%N') * 1000))
As bash
(and other shells) does not support floating point arithmetic, you can use bc
instead. 由于bash
(和其他shell)不支持浮点运算,因此可以改用bc
。
Example: 例:
% echo $(($(date '+%s') * 1000))
1462194433000
% echo $(($(date '+%s.%N') * 1000))
1462194596950.2983
% printf '%.2f\n' $(($(date '+%s.%N') * 1000))
1462194696479.11
您可以测试scrptine 。我认为它可以为您提供帮助。
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 然后,脚本调用语言的解释器以运行脚本中的代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.