私は現在、bash スクリプトを書いています。if コマンドが 2 つあります。ここでは問題をうまく説明できないので、コードで説明します。
#!/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.
答え1
if elif および else をチェーン リンクと考えてください。if は開始、elif は中間リンク、else は終了リンクです。記述したのは、「開始、中間リンク、終了リンク、終了リンク」です。5 行目と 14 行目の if を分離するには、ネストされた if が必要です。
私の提案は次のようになります
#!/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