2014-04-09 86 views
1

我在使用Bash语法时遇到问题,希望有些大师能够帮助我解决问题。Bash执行时间错误

bash的是:

(sort | grep po | wc) </etc/passwd> out ; cat out 

exec /usr/bin/time -f "real %e user %U sys %S maxmem %M" (sort | grep po | wc) </etc/passwd> out; cat out 

第一行运行正常。第二行给出了错误:

./sh: line 2: syntax error near unexpected token `(' 
./sh: line 2: `exec time (sort | grep po | wc) </etc/passwd> out' 

我试图让1号线在:

exec /usr/bin/time -f "real %e user %U sys %S maxmem %M" --Line 1 Solution Here-- 

形式。

我已经试过了我能想到的所有引用内容,并且似乎无法实现。作为一个侧面提示,删除-f和参数以及前面的exec将允许它运行,但在我的场景中,我需要它们处于最终解决方案中。

由于我在这里尝试了很多东西,尝试在它周围放置双引号的反应,试试这个或试试会得到否定的投票。

回答

0
exec /usr/bin/time -f "real %e user %U sys %S maxmem %M" /bin/bash -c 'sort | grep po | wc' </etc/passwd> out; cat out 

感谢当地的同事。

+0

请注意,这是可行的,因为'/ usr/bin/time'需要一个可执行文件作为它的参数,而不是一个任意的shell命令。 – chepner