Ich schreibe gerade ein Bash-Skript. Ich habe zwei if-Befehle. Ich kann das Problem hier nicht wirklich beschreiben, also werde ich mein Problem in Codes beschreiben
#!/bin/bash
echo -e "What is the SGID?"
read Cevap50
if [ ! -f /home/fixscript/AudioBot$audiobot_port/.adminlikler_sgid_silmeyin ]
then
rm -rf .rights.toml
touch .adminlikler_sgid_silmeyin
echo -ne "$Cevap50" >> .adminlikler_sgid_silmeyin
adminlikler_sgid=`cat .adminlikler_sgid_silmeyin`
rights_bir
echo " groupid = [ $adminlikler_sgid ]" >> .rights.toml
echo ' # And/Or your admin Client Uids here' >> .rights.toml
elif [ ! -f /home/fixscript/AudioBot$audiobot_port/.adminlikler_uid_silmeyin ]
then
echo " useruid = []" >> .rights.toml
rights_iki
clear
else #There is the problem, this else should affect line 14th's if. But it just effects both of them.
#Some Codes
else #This else should affect line 5th's if.
Antwort1
Stellen Sie sich if elif und else als Kettenglieder vor, wobei if der Anfang, elifs die Mittelglieder und else das Endglied sind. Sie haben „Anfang, Mittelglied, Endglied, Endglied“ geschrieben. Um die ifs in Zeile 5 und 14 zu trennen, suchen Sie nach verschachtelten ifs.
Mein Vorschlag wäre also folgender
#!/bin/bash
echo -e "What is the SGID?"
read Cevap50
if [ ! -f /home/fixscript/AudioBot$audiobot_port/.adminlikler_sgid_silmeyin ]
then
rm -rf .rights.toml
touch .adminlikler_sgid_silmeyin
echo -ne "$Cevap50" >> .adminlikler_sgid_silmeyin
adminlikler_sgid=`cat .adminlikler_sgid_silmeyin`
rights_bir
echo " groupid = [ $adminlikler_sgid ]" >> .rights.toml
echo ' # And/Or your admin Client Uids here' >> .rights.toml
else #Effects line 5's if.
if [ ! -f /home/fixscript/AudioBot$audiobot_port/.adminlikler_uid_silmeyin ]
then
echo " useruid = []" >> .rights.toml
rights_iki
clear
else # Effects line 15's if