Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/349.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python到Shell脚本?_Shell_Python - Fatal编程技术网

Python到Shell脚本?

Python到Shell脚本?,shell,python,Shell,Python,如何将这个简单的python代码转换为Shell脚本 import time import sys cur_time = int(time.time()*1000) print cur_time sys.exit(1) 你可以测试。我认为它可以帮助你。你可以测试。我认为它可以帮助你。它只是将历代以来的秒数乘以1000(增加了纳秒精度) 你可以做: $(($(date '+%s') * 1000)) 纳秒精度,在zsh: $(($(date '+%s.%N') *

如何将这个简单的python代码转换为Shell脚本

   import time
   import sys
   cur_time = int(time.time()*1000)
   print cur_time
   sys.exit(1)

你可以测试。我认为它可以帮助你。

你可以测试。我认为它可以帮助你。

它只是将历代以来的秒数乘以1000(增加了纳秒精度)

你可以做:

$(($(date '+%s') * 1000))
纳秒精度,在
zsh

$(($(date '+%s.%N') * 1000))
printf '%.2f\n' $(($(date '+%s.%N') * 1000))
精度为2个小数点,单位为
zsh

$(($(date '+%s.%N') * 1000))
printf '%.2f\n' $(($(date '+%s.%N') * 1000))
由于
bash
(和其他shell)不支持浮点运算,因此可以使用
bc

示例:

% echo $(($(date '+%s') * 1000))
1462194433000

% echo $(($(date '+%s.%N') * 1000))
1462194596950.2983

% printf '%.2f\n' $(($(date '+%s.%N') * 1000))
1462194696479.11

它只是将历代以来的秒数乘以1000(再加上一些纳秒精度)

你可以做:

$(($(date '+%s') * 1000))
纳秒精度,在
zsh

$(($(date '+%s.%N') * 1000))
printf '%.2f\n' $(($(date '+%s.%N') * 1000))
精度为2个小数点,单位为
zsh

$(($(date '+%s.%N') * 1000))
printf '%.2f\n' $(($(date '+%s.%N') * 1000))
由于
bash
(和其他shell)不支持浮点运算,因此可以使用
bc

示例:

% echo $(($(date '+%s') * 1000))
1462194433000

% echo $(($(date '+%s.%N') * 1000))
1462194596950.2983

% printf '%.2f\n' $(($(date '+%s.%N') * 1000))
1462194696479.11

你可以改变任务

 chmod +x file
并在第一行中添加

#!/usr/bin/env python

如果我是对的,它用来呼叫没有前面的语言。然后脚本调用语言的解释器来运行脚本中的代码

您可以更改命令

 chmod +x file
并在第一行中添加

#!/usr/bin/env python

如果我是对的,它用来呼叫没有前面的语言。然后脚本调用语言的解释器来运行脚本中的代码

date+%s
传递:
%s
这不会改变任何事情。打印当前时间值的更方便的方法是运行
awk'BEGIN{srand();print srand()}
date+%s
传递:
%s
这不会改变任何事情。打印当前时间值的更方便的方法是运行
awk'BEGIN{srand();print srand()}