if 语句:'fi' 意外

if 语句:'fi' 意外

我用 if 语句制作了一个 shell,所有换行符都是 LF (Linux),当我尝试执行 shell 时,我收到“语法错误:‘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

两段时间,只有一次做+完成

相关内容