我经常使用 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
如何在脚本中使用时间
?
最佳答案
bash
将time
定义为前置命令修饰符; /bin/sh
只是在运行外部命令 time
。您可能希望将 #!/bin/bash
作为您的 shebang。
关于linux - 如何在 shell 脚本中使用 `time` 命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50490810/