I wanted to create a bash script to achieve a particular task although i have no knowledge of bash. Lazily asking it here directly wouldn't have have explained my question well , so i just kept struggling for 1 hour and got as far as i could so that there's atleast a basic structure of my code ( even tho possibly broken but still it would easier to get my question so more people will be willing to help ).
First lemme show exactly the error which i am getting
$ su
$ sh "/sdcard/tester.sh"
/sdcard/tester.sh[2]: syntax error: 'if' unmatched
Code below
#!/bin/bash
PACKAGE='com.mixplorer'
if [ $(pidof $PACKAGE) ]; then
am force-stop com.mixplorer
am start -n com.mixplorer/.activities.BrowseActivity
loopcleaner()
{
rm -rf /sdcard/log.txt
}
while [ $(pidof $PACKAGE) ]
do
loopcleaner
sleep 10
if [ ! $(pidof $PACKAGE) ]; then
break
mkdir /sdcard/successful.txt
fi
done
Explanation of what i am trying to achieve:
1) As soon as script is executed , first check if file manager with package name 'com.mixplorer' process is already active If yes , then force stop it and open it again If no , then just simply open it
2) Now that the file manager is already opened , keep deleting a file named 'log.txt' as defined by loopcleaner every 10 seconds in a loop forever as long as file manager process is running
3) Only after file manager process is no longer active , end the loop cleaning process from step 2 and create a file named successful.txt . After creating this file , script should end / kill its own process
fi
for the firstif
https://shellcheck.net
, a syntax checker, or installshellcheck
locally. Make usingshellcheck
part of your development process.