【发布时间】:2014-04-04 12:01:54
【问题描述】:
我正在尝试处理来自 for 循环中命令的意外输出。我正在使用专有的解压缩实用程序 (mfunzip),但是当该实用程序遇到损坏的文件时,它开始回显无休止的“InputBit 中的致命错误!”消息。
我正在尝试捕获输出并继续循环到下一个文件。
for FILE in $(ls); do
if [ -d "$FILE" ]; then
...
...
# without command output, it runs indefinitely
output=$(mfunzip $currentfile $extractdir)
# it never reaches here
echo $output
if [[ $output = *Fatal* ]]; then
continue
fi
fi
done
但是它似乎没有工作,因为它阻塞在 output=$(mfunzip ... ) ...我假设它无休止地输出到 $output .另一个问题似乎是“致命错误”可能不会立即出现,而是在尝试 mfunzip 文件的中途出现。
有没有更好的方法来处理这种类型的输出?
【问题讨论】:
-
与您的问题无关,但使用 * 而不是 $(ls) 更安全。
-
Abhishek 这不是来自服务器的实际脚本,我只是快速在“some”文件夹中创建了一个 for 过程的模型以显示问题所在。 :)
-
请发布实际重现您的问题的代码。你的模型代码很好;它可能遇到的唯一问题是
mfunzip永远不会完成。
标签: bash error-handling hp-ux