My apologies if my issue has already been asked in other posts, but I wasn't able to find any. I am writing a little shell script which requires me to write a nested if statement. I am not really sure I am doing it right. I get no errors, but the program isn't functioning as I expect it. What I want is: If the file is already in MasterFile.txt, then the user has the option to either take another set of data by saying y or Y, or say n or N to terminate the program. Problem: Script does not terminate. If the file does not exist in MasterFile.txt, then take the data set. Here's the code:
if grep -q "dicounter_${string1}_from_${string2}" MasterFile.txt;
then {
echo "dicounter_${string1}_from_${string2} already exists in the MasterFile. Would you like to proceed?"
read string3
if "${string3}" = 'Y' || "${string3}" = 'y'; then {
screen -S trans -L /dev/ttyACM0
screen -S trans -X stuff 's'$(echo -ne '\015')
sleep 8s
screen -S trans -X quit
}
else{return}
fi
else{
#opening screen & begin analysis
screen -S trans -L /dev/ttyACM0
screen -S trans -X stuff 's'$(echo -ne '\015')
sleep 8s
screen -S trans -X quit
}
fi
sh-type shells don't use{ ... }for blocks.{...}is the problem. There must be something wrong with the way I implemented the nestedifelsestatementif "${string3}" = 'Y'takes the contents ofstring3as the name of a command, and runs it with two arguments=andY...