linux - 如何在 shell 脚本中使用 `time` 命令?

标签 linux bash

我经常使用 time 通过控制台为命令计时:

time PGPASSWORD=postgres psql -U postgres -h localhost -f init.sql

我现在创建了一个执行相同操作的 shell 脚本:

#!/bin/sh
time PGPASSWORD=postgres psql -U postgres -h localhost -f init.sql

现在我得到以下错误:

time: cannot run PGPASSWORD=postgres: No such file or directory
Command exited with non-zero status 127

如何在脚本中使用时间

最佳答案

bashtime定义为前置命令修饰符; /bin/sh 只是在运行外部命令 time。您可能希望将 #!/bin/bash 作为您的 shebang。

关于linux - 如何在 shell 脚本中使用 `time` 命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50490810/

相关文章:

c++ - MEX编译错误

html - 如何在bash中仅使用grep提取html标签

regex - linux查找正则表达式

linux - 使用 awk linux 操作文件

linux - 使用 CMAKE 编译静态可执行文件

c - regcmp 模式 $0 含义

linux - 为什么RTL8139有四个Tx描述符?

linux - bash - 只有当相应的文本文件存在时才打开图像

linux - 恢复 .bak 文件

linux - 通过 IFTTT 在树莓派中运行 bash 脚本