-2

I'm currently writing a bash script. I do have a two if commands. I cant really describe the problem here so I'm gonna describe my problem in codes

#!/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.
2
  • Hello. You can't expect us to guess what your problem is by inserting some random code and stating "I cant really describe the problem"... I imagine you have to do better if you expect anyone to help you. Aug 5, 2022 at 12:28
  • Always paste your script into https://shellcheck.net, a syntax checker, or install shellcheck locally. Make using shellcheck part of your development process.
    – waltinator
    Aug 5, 2022 at 12:31

1 Answer 1

3

Think of if elif and else as chain links, if is the beginning, elifs are the middle links and else is the end link. What you've written is "beginning, middle link, end link, end link". In order to separate ifs at line 5 and 14, what you are looking for is nested if.

So my suggestion would be like this

#!/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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.