如何从查找管道循环中退出脚本?
E.g。以下退出只退出管道子shell:
find some_directory -type d|while read dir_name; do
if [ -w "$dir_name" ]; then
exit 1
fi
done
答案 0 :(得分:2)
您可以检查管道的返回状态:
find some_directory -type d|while read dir_name; do
[ -w "$dir_name" ] && exit 1
done || exit 1
或者更简单:
private Map <Integer, Integer> map = new HashMap<>();