if statement: 'fi' unexpected

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












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 movednnTo fix that:n- We back to main menun- Select rs option to restore a specifiq game file in your internal storagen- 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 '%sn' $dirs | sed -r -e 's//storage/emulated/0/Android/obb///' | awk -f. 'print $NF' | sed -r -e 's////'`
while printf '%sn' "$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 closednReady for next step...'$N; sleep 4;
else
echo -n -e $C'No game run in background on your devicenNext 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 sdcardnNB: You could even see files in your internal storage, but they are just linkedn'$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).










share|improve this question























  • See the double while in while printf '%sn' "$APPSNAMES" | while IFS= read -r line, only one of which has a corresponding do/done.
    – Stéphane Chazelas
    Sep 25 at 10:54







  • 5




    yet another plug for shellcheck.net
    – Jeff Schaller
    Sep 25 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 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 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 at 11:27














up vote
0
down vote

favorite












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 movednnTo fix that:n- We back to main menun- Select rs option to restore a specifiq game file in your internal storagen- 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 '%sn' $dirs | sed -r -e 's//storage/emulated/0/Android/obb///' | awk -f. 'print $NF' | sed -r -e 's////'`
while printf '%sn' "$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 closednReady for next step...'$N; sleep 4;
else
echo -n -e $C'No game run in background on your devicenNext 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 sdcardnNB: You could even see files in your internal storage, but they are just linkedn'$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).










share|improve this question























  • See the double while in while printf '%sn' "$APPSNAMES" | while IFS= read -r line, only one of which has a corresponding do/done.
    – Stéphane Chazelas
    Sep 25 at 10:54







  • 5




    yet another plug for shellcheck.net
    – Jeff Schaller
    Sep 25 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 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 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 at 11:27












up vote
0
down vote

favorite









up vote
0
down vote

favorite











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 movednnTo fix that:n- We back to main menun- Select rs option to restore a specifiq game file in your internal storagen- 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 '%sn' $dirs | sed -r -e 's//storage/emulated/0/Android/obb///' | awk -f. 'print $NF' | sed -r -e 's////'`
while printf '%sn' "$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 closednReady for next step...'$N; sleep 4;
else
echo -n -e $C'No game run in background on your devicenNext 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 sdcardnNB: You could even see files in your internal storage, but they are just linkedn'$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).










share|improve this question















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 movednnTo fix that:n- We back to main menun- Select rs option to restore a specifiq game file in your internal storagen- 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 '%sn' $dirs | sed -r -e 's//storage/emulated/0/Android/obb///' | awk -f. 'print $NF' | sed -r -e 's////'`
while printf '%sn' "$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 closednReady for next step...'$N; sleep 4;
else
echo -n -e $C'No game run in background on your devicenNext 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 sdcardnNB: You could even see files in your internal storage, but they are just linkedn'$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).







shell-script busybox






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 25 at 11:08









Vlastimil

6,8411149123




6,8411149123










asked Sep 25 at 10:50









Rom

113




113











  • See the double while in while printf '%sn' "$APPSNAMES" | while IFS= read -r line, only one of which has a corresponding do/done.
    – Stéphane Chazelas
    Sep 25 at 10:54







  • 5




    yet another plug for shellcheck.net
    – Jeff Schaller
    Sep 25 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 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 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 at 11:27
















  • See the double while in while printf '%sn' "$APPSNAMES" | while IFS= read -r line, only one of which has a corresponding do/done.
    – Stéphane Chazelas
    Sep 25 at 10:54







  • 5




    yet another plug for shellcheck.net
    – Jeff Schaller
    Sep 25 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 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 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 at 11:27















See the double while in while printf '%sn' "$APPSNAMES" | while IFS= read -r line, only one of which has a corresponding do/done.
– Stéphane Chazelas
Sep 25 at 10:54





See the double while in while printf '%sn' "$APPSNAMES" | while IFS= read -r line, only one of which has a corresponding do/done.
– Stéphane Chazelas
Sep 25 at 10:54





5




5




yet another plug for shellcheck.net
– Jeff Schaller
Sep 25 at 10:56




yet another plug for shellcheck.net
– Jeff Schaller
Sep 25 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 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 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 at 11:02




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 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 at 11:27




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 at 11:27










1 Answer
1






active

oldest

votes

















up vote
0
down vote













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



 while printf '%sn' "$APPSNAMES" | while IFS= read -r line


Two whiles and only one do+done






share|improve this answer




















  • The for dirs in "$INTFOLD" also has no done
    – Stéphane Chazelas
    Sep 25 at 11:27










  • Thank you @Alexander it works now.
    – Rom
    Sep 25 at 19:15










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f471293%2fif-statement-fi-unexpected%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













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



 while printf '%sn' "$APPSNAMES" | while IFS= read -r line


Two whiles and only one do+done






share|improve this answer




















  • The for dirs in "$INTFOLD" also has no done
    – Stéphane Chazelas
    Sep 25 at 11:27










  • Thank you @Alexander it works now.
    – Rom
    Sep 25 at 19:15














up vote
0
down vote













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



 while printf '%sn' "$APPSNAMES" | while IFS= read -r line


Two whiles and only one do+done






share|improve this answer




















  • The for dirs in "$INTFOLD" also has no done
    – Stéphane Chazelas
    Sep 25 at 11:27










  • Thank you @Alexander it works now.
    – Rom
    Sep 25 at 19:15












up vote
0
down vote










up vote
0
down vote









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



 while printf '%sn' "$APPSNAMES" | while IFS= read -r line


Two whiles and only one do+done






share|improve this answer












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



 while printf '%sn' "$APPSNAMES" | while IFS= read -r line


Two whiles and only one do+done







share|improve this answer












share|improve this answer



share|improve this answer










answered Sep 25 at 11:24









Alexander

86213




86213











  • The for dirs in "$INTFOLD" also has no done
    – Stéphane Chazelas
    Sep 25 at 11:27










  • Thank you @Alexander it works now.
    – Rom
    Sep 25 at 19:15
















  • The for dirs in "$INTFOLD" also has no done
    – Stéphane Chazelas
    Sep 25 at 11:27










  • Thank you @Alexander it works now.
    – Rom
    Sep 25 at 19:15















The for dirs in "$INTFOLD" also has no done
– Stéphane Chazelas
Sep 25 at 11:27




The for dirs in "$INTFOLD" also has no done
– Stéphane Chazelas
Sep 25 at 11:27












Thank you @Alexander it works now.
– Rom
Sep 25 at 19:15




Thank you @Alexander it works now.
– Rom
Sep 25 at 19:15

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f471293%2fif-statement-fi-unexpected%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay