我正在尝试编写一个在FreeBSD上执行2个脚本的for循环.我不在乎它是用sh还是csh写的.我想要的东西:
for($i=11; $i<=24; $i++) { exec(tar xzf 'myfile-1.0.' . $i); // detect an error was returned by the script if ('./patch.sh') { echo "Patching to $i failed\n"; } }
有人知道怎么做吗?
谢谢
csh做的循环很好,问题是你使用的是exec,它在同一个进程中用不同的程序替换当前程序(也就是shell).由于其他人提供了sh版本,这里有一个csh:
#!/bin/csh set i = 11 while ($i < 25) tar xzf "myfile-1.0.$i" # detect an error was returned by the script if ({./patch.sh}) then echo "Patching to $i failed" endif @ i = $i + 1 end
不确定./patch.sh你是在测试它的存在还是运行它?我在这里运行它,并测试结果 – true表示它返回零.或者:
# detect an error was returned by the script if (!{tar xzf "myfile-1.0.$i"}) then echo "Patching to $i failed" endif
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。