if文: 'fi'予期しない結果

if文: 'fi'予期しない結果

ifステートメントを使用してシェルを作成し、すべての改行文字がLF(Linux)であり、シェルを実行しようとすると、「構文エラー: 'fi'予期しない」エラーが発生します。

if [ "$(ls -A /storage/$SDCARD_DIR/Android/obb/*/)" ]; then
    echo -n -e $Y'One of games folders on your external SDCard has been already moved\n\nTo fix that:\n- We back to main menu\n- Select rs option to restore a specifiq game file in your internal storage\n- Try again to the ma option to move all your games files to your external sdcard'$N
    clear && main_menu
else
    echo -n -e $C"For info: it's necessary to forcing games apps to be closed"$N; sleep 8;

   APPSNAMES=`for dirs in "$INTFOLD"; do printf '%s\n' $dirs | sed -r -e 's/\/storage\/emulated\/0\/Android\/obb\///' | awk -f. '{print $NF}' | sed -r -e 's/\///'`
   while printf '%s\n' "$APPSNAMES" | while IFS= read -r line
    do
        if [ -z $(ps | grep "$line") ]; then
            xargs kill
            echo -n -e $Y'Game(s) app(s) has been closed\nReady for next step...'$N; sleep 4;
        else
            echo -n -e $C'No game run in background on your device\nNext step now..'$N; sleep 4;
        fi
   done

   echo -n -e $B'Move all your games to your external SCard...'$N; sleep 5;
   for D in `find /storage/emulated/0/Android/obb/ -maxdepth 1 -type d`
    do cp -af $D $EXSDCARD
   done
   for F in `find /storage/emulated/0/Android/obb/ -type f`
    do rm -f $F
   done
   for X in `find "$EXSDCARD" -type F`
    do ln -s $X $EXSDCARD
   done
   echo -n -e $G'All OBB files are now moved to your sdcard\nNB: You could even see files in your internal storage, but they are just linked\n'$N; sleep 7;
   echo -n -e $B'Back to main menu...'$N; sleep 5;
main_menu
fi

このエラーが発生する理由を理解できません。 Android環境でこのスクリプトを使用しており、Termux、Busyboxを使用しており、rootアクセス権があることを指摘したいと思います。

同じ問題を持つ複数のユーザースレッドを調べましたが、問題は見つかりませんでした。

ベストアンサー1

私が嫌う唯一のことは(間違っているように見える)ことです。

 while printf '%s\n' "$APPSNAMES" | while IFS= read -r line

2つの期間、一度だけ実行+完了

おすすめ記事