0

I tried reading up on this, but am unable to find anything fixing my issue.. Issue is: I have a nested while loop and the inner is being skipped completely. The outter loop runs fine and the inner code does work as expected when taken out and run on its own. I'm new to this, so just looking for a straight forward way to fix, not necessarily a way to re-write everything (unless necessary) haha. I omitted a few things replacing with generic [command], etc.

guid=0
procedure=0
olcmd="${userbin}/[command] ${guid}"

guidver=true;
while $guidver; do
    guidver=false;
    read -p "
Input log GUID below and press 'Enter'?
"   guid
    if [[ $guid == ????????-????-????-????-???????????? ]]; then
        printf "Good GUID, continuing\n";
    else echo "Bad value, please use only Index GUIDs."; guidver=true
    olver=true;
    while $olver; do
        olver=false;
        if $olcmd | grep -i '[text]'>/dev/null; then
        printf "\n[text]\n\n"
            continue
#       guidver=false;
        else printf "\n[text]\n\n"
        olver=true;
        break
        fi
    done
    fi
done

I really appreciate any help!

1 Answer 1

1

Your indentation is misleading:

Check your code with proper indentation

guid=0
procedure=0
olcmd="${userbin}/[command] ${guid}"

guidver=true;
while $guidver; do
    guidver=false;
    read -p "
    Input log GUID below and press 'Enter'?
    "   guid
    if [[ $guid == ????????-????-????-????-???????????? ]]; then
        printf "Good GUID, continuing\n";
    else echo "Bad value, please use only Index GUIDs."; 
        guidver=true
        olver=true;
        while $olver; do
            olver=false;
            if $olcmd | grep -i '[text]'>/dev/null; then
                printf "\n[text]\n\n"
                    continue
                #       guidver=false;
            else printf "\n[text]\n\n"
                olver=true;
                break
            fi
        done
    fi
done

See? Your second while is inside the else branch of your first if statement

I think, what you meant would be

guid=0
procedure=0
olcmd="${userbin}/[command] ${guid}"

guidver=true;
while $guidver; do
    guidver=false;
    read -p "
    Input log GUID below and press 'Enter'?
    "   guid
    if [[ $guid == ????????-????-????-????-???????????? ]]; then
        printf "Good GUID, continuing\n";
    else echo "Bad value, please use only Index GUIDs."; 
        guidver=true
    fi

    olver=true;
    while $olver; do
        olver=false;
        if $olcmd | grep -i '[text]'>/dev/null; then
            printf "\n[text]\n\n"
                continue
            #       guidver=false;
        else printf "\n[text]\n\n"
            olver=true;
            break
        fi
    done
done
Sign up to request clarification or add additional context in comments.

1 Comment

Ah YES I was trying to analyze exactly where the inside loop was placed, wondering if it was a conflict being within the other if function, but didn't try the simple solution of just moving it down. I had to tweak a couple more things such as adding guidver=true on the inside loop to kick it back up to the outer until an acceptable GUID was passed. Now working as I had hoped. Thanks very much, I do appreciate it!

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.