0
我有一個使用嵌套的if-else語句來搜索文件的腳本。我希望腳本在任何一個嵌套語句符合條件時退出。如何在遇到條件時從嵌套的if-else語句中退出/斷開
但腳本仍然繼續運行所有其餘的if-else語句。
我已經測試過使用退出0並返回0,但都不起作用。
這裏的腳本:
#!/bin/sh
PATH1=/filer1_vol1_dir1
PATH2=/filer2_vol1_dir1
PATH3=/filer3_vol1_dir2
PATTERN=fruits
find $PATH1 -type f -name "*$PATTERN*" -exec ls -l {} \; >> /tmp/${PATTERN}_search
if [[ -s /tmp/${PATTERN}_search && `grep -i apples /tmp/${PATTERN}_search` ]]
then
echo "Matching files have been found under $PATH1"
cat /tmp/${PATTERN}_search
return 0
else
echo "No matching files, proceeding to search $PATH2"
find $PATH2 -type f -name "*$PATTERN*" -exec ls -l {} \; >> /tmp/${PATTERN}_search
if [[ -s /tmp/${PATTERN}_search && `grep -i apples /tmp/${PATTERN}_search` ]]
then
echo "Matching files have been found under $PATH2"
cat /tmp/${PATTERN}_search
return 0
else
echo "No matching files, proceeding to search $PATH3"
find $PATH3 -type f -name "*$PATTERN*" -exec ls -l {} \; >> /tmp/${PATTERN}_search
if [[ -s /tmp/${PATTERN}_search && `grep -i apples /tmp/${PATTERN}_search` ]]
then
echo "Matching files have been found under $PATH3"
cat /tmp/${PATTERN}_search
return 0
else
echo "No file matches, please search elsewhere"
return 0
fi
fi
fi
exit 0