处理意外的bash命令输出



我正试图处理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

然而,它似乎不起作用,因为它在输出=$(mfunzip…)处阻塞。。。我假设它无休止地输出到$output。另一个问题似乎是"致命错误"可能不会立即出现,而是在尝试mfunzip文件的中途出现。

有没有更好的方法来处理这种类型的输出?

要"处理命令的(意外或预期)输出",您应该使用:http://en.wikipedia.org/wiki/Expect,是专门为这类东西设计的。

最新更新