Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8985403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:19:21+00:00 2026-06-15T21:19:21+00:00

Trying to understand what is happening here and why? The function named why gets

  • 0

Trying to understand what is happening here and why?

The function named “why” gets called first then then the results should be either another call to the function or a complete exit. The expected results is never being able to run the loop below the if statement, which could be an if-else-fi statement or if-elif-else-fi and does not matter.

The question is why does it echo end?

I do not understand why the last echo is ever able to be called.

why ()  {
  read -p 'Loop now?  [y/n]' answer
      case $answer in
        y | Y | yes | YES ) answer="y";;
        *) exit;;
       esac
}

if [ $answer = 'y' ]
then
    why
fi
why 
echo "End"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:19:22+00:00Added an answer on June 15, 2026 at 9:19 pm

    The if statement considers it self done at the time the function completes. It is better shown in this example and the script will not loop back to the echo start.

    echo start
    why ()  {
      read -p 'Loop now?  [y/n]' answer
          case $answer in
            y | Y | yes | YES ) answer="y";;
            *) echo 'Invalid response -- exiting now'
               exit;;
           esac
    }
    
    answer=y
    
    if [ $answer = 'y' ]
    then
    
        why
        echo "Ok done running the if statement ready to exit the condition now"
    fi
    

    So to loop back and forth a function to wrap the if statement is used as shown here:

    echo start
    why ()  {
      read -p 'Loop now?  [y/n]' answer
          case $answer in
            y | Y | yes | YES ) answer="y";;
            n | N | no | NO ) answer="n";;
            *) echo 'Invalid response -- exiting now'
               exit;;
           esac
      ifFunction
    }
    
    ifFunction () { 
      if [ $answer = 'y' ]
      then
    
        why
        echo "yes"
      elif [ $answer = 'n' ]
      then
        echo "to bad looping anyway"
        why
      else
        echo "else nothing but another question"
        why
      fi
    }
    why
    echo never
    

    So the answer is it has completed the function and now moves on through the script as expected, which in the example provided would have echoed end as the next task to complete.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to understand what's happening here: I have a supervisor that is cyclically
I am trying to understand what is happening in the getter below, this is
I've been trying for 3 hours and I just can't understand what is happening
I don't really understand why this is happening at all. I'm trying to open
I being for the last 12 hours trying to understand why this is happening.
I am trying to understand the working of the built-in sum() function, but, the
I am trying to understand what the STL time series function does and in
I simply cannot understand what is happening here. The problem is important for my
I am trying understand ViewModels deeper and I have read many articles and blogs
Trying to understand what's the correct way of implementing OpenID authentication with Spring Security.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.