0

I have made a shell with an if statment, all newline characters are LF (Linux), when i try to execute the shell, i get an "syntax error: 'fi' unexpected".

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

I don't understand why i get this error, i would like to point out that i use this script on Android environment with Termux, Busybox and got root access.

I have already check several threads of users with the same issue but i don't find any error(s).

  • See the double while in while printf '%s\n' "$APPSNAMES" | while IFS= read -r line, only one of which has a corresponding do/done. – Stéphane Chazelas Sep 25 '18 at 10:54
  • 5
    yet another plug for shellcheck.net – Jeff Schaller Sep 25 '18 at 10:56
  • When assigning to APPSNAMES you use a for loop. This loop is never closed. Also see unix.stackexchange.com/questions/321697 – Kusalananda Sep 25 '18 at 10:56
  • There are a total of five do in the code, but only four done. At the same time, there are six for or while. – Kusalananda Sep 25 '18 at 11:02
  • Thank you very much StéphaneChazelas , thanks Jeff Schaller for the website and Kusalananda for his fixs, effectivly some of my loops didn't have their done. – Rom Sep 25 '18 at 11:27
0

The only think I don't like (can see is wrong) is

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

Two whiles and only one do+done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.