While loop in BASH script causing syntax error -


i started writing bash scripts, , trying practice using while loops. however, when run following block of code, command prompt responds with:

run.command: line 12: syntax error near unexpected token `done' run.command: `done' 

then program shuts off. code running.

#!/bin/bash echo -e "text" c=false while true;     printf ">> "     i=read      if [$i = "exit"];         exit     else if [$i = "no"];         echo "no"     else         echo -e "error: $i undefined"     fi done 

i did research on while loops, loop syntax seems correct. when remove done @ end, , unexpected end of file error occurs. appreciated!

you can use -p option of read prompt , case ... esac construction:

while true;   read -r -p ">> "   case "$i" in      "exit") exit 0  ;;      "no") echo "no" ;;      *) echo -e "error: $i undefined";;   esac done 

Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -