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

  • Home
  • SEARCH
  • 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 1021779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:21:45+00:00 2026-05-16T11:21:45+00:00

while [ $done = 0 ] do echo -n Would you like to create

  • 0
while [ $done = 0  ]
  do
  echo -n "Would you like to create one? [y/n]: "
  read answer
  if [ "$(answer)" == "y" ] || [ "$(answer)" == "Y" ]; then
    mkdir ./fsm_$newVersion/trace
    echo "Created trace folder in build $newVersion"
    $done=1
  elif [ "$(answer)" == "n" ] || [ "$(answer)" == "N" ]; then
    $done=2
  else
    echo "Not a valid answer"
  fi
done

Ok so I have this simple bashscript above that simply just tries to get input from a user and validate it. However I keep getting this error

./test.sh: line 1: answer: command not found
./test.sh: line 1: answer: command not found
./test.sh: line 1: answer: command not found
./test.sh: line 1: answer: command not found

Which I have no idea why because “answer” is nowhere near line 1. So I ran into this article

Which makes sense since it’s referring to line 1 and can’t find answer. So it seems to be starting a new subshell. However I didn’t really understand the solution and can’t see how I would apply it to my case. I just wanna get this to work.

  • 1 1 Answer
  • 3 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-05-16T11:21:46+00:00Added an answer on May 16, 2026 at 11:21 am

    $(answer) doesn’t substitute the value of the variable answer. It executes answer as a command, and substitutes the output of that command. You want ${answer} everywhere you have $(answer). In this case you can get away with bare $answer too, but overuse of ${...} is good paranoia.

    (Are you perhaps used to writing Makefiles? $(...) and ${...} are the same in Makefiles, but the shell is different.)

    By the way, you have some other bugs:

    • In shell, you do not put a dollar sign on the variable name on the left hand side of an assignment. You need to change $done=1 to just done=1 and similarly for $done=2.
    • You are not being paranoid enough about your variable substitutions. Unless you know for a fact that it does the wrong thing in some specific case, you should always wrap all variable substitutions in double quotes. This affects both the mkdir command and the condition on the while loop.
    • You are not being paranoid enough about arguments to test (aka [). You need to prefix both sides of an equality test with x so that they cannot be misinterpreted as switches.
    • == is not portable shell, use = instead (there is no difference in bash, but many non-bash shells do not support == at all).

    Put it all together and this is what your script should look like:

    while [ "x${done}" = x0 ]; do
      echo -n "Would you like to create one? [y/n]: "
      read answer
      if [ "x${answer}" = xy ] || [ "x${answer}" = xY ]; then
        mkdir "./fsm_${newVersion}/trace"
        echo "Created trace folder in build $newVersion"
        done=1
      elif [ "x${answer}" = xn ] || [ "x${answer}" = xN ]; then
        done=2
      else
        echo "Not a valid answer"
      fi
    done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say you have a simple loop while read line do printf ${line#*//}\n done <
So I'm trying to do something like the following: while read line; do read
I have a table of dictionary terms and now I would like to create
i would like create a menu with kdialog like this kdialog --menu choose your
I would like to read a file into a script, line by line. Each
I have been building a game for a while (nearly done) - But the
I have done simple java app for blackberry, while building am getting following error.
I haven't done any swing programming in a while, so I'm looking for some
code: path=$PATH: while [ -n $path ] do ls -ld ${path%%:*} path=${path#*:} done I
I want to display a progress animation while updatepanel's work being done, but without

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.