[英]How can I use the `time` command IN a shell script?
I often use time
to time a command via console: 我经常使用
time
通过控制台来计时命令:
time PGPASSWORD=postgres psql -U postgres -h localhost -f init.sql
I now created a shell script which does the same: 我现在创建了一个shell脚本,它执行相同的操作:
#!/bin/sh
time PGPASSWORD=postgres psql -U postgres -h localhost -f init.sql
Now I get the following error: 现在我得到以下错误:
time: cannot run PGPASSWORD=postgres: No such file or directory
时间:无法运行PGPASSWORD = postgres:没有此类文件或目录
Command exited with non-zero status 127命令以非零状态退出127
How can I use time
in a script? 如何在脚本中使用
time
?
bash
defines time
as a pre-command modifier; bash
将time
定义为命令前修饰符; /bin/sh
is just running the external command time
. /bin/sh
只是在运行外部命令time
。 You probably want #!/bin/bash
as your shebang. 您可能想要
#!/bin/bash
作为您的shebang。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.