Find the answer to your Linux question:
Results 1 to 2 of 2
my while loop shows this error...pls help me...urgent.unexpected token done for ((i=1; i<=n; i++)) do v=${A[$i]} j=` expr $i - 1` while [ $j -ge 0 ] do while [ ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2010
    Posts
    3

    Question unexpected token done


    my while loop shows this error...pls help me...urgent.unexpected token done



    for ((i=1; i<=n; i++)) do
    v=${A[$i]}
    j=` expr $i - 1`
    while [ $j -ge 0 ] do
    while [ ${A[$j]} -gt $v ] do
    c=` expr $j + 1`
    A[$c]=${A[$j]}
    j=` expr $j - 1`
    done
    done
    d=` expr $j + 1`
    A[$d]=$v
    done

  2. #2
    Linux User
    Join Date
    Nov 2009
    Location
    France
    Posts
    292
    You should add a semi-colon before do statements :

    Code:
    for ((i=1; i<=n; i++)); do
    ...
    while [ $j -ge 0 ]; do
    
    or 
    
    for ((i=1; i<=n; i++))
    do
    ...
    while [ $j -ge 0 ]
    do
    Running the script correctly syntaxed resulted in bad index array errors. Any way, it's too twisty to be easily followed.
    0 + 1 = 1 != 2 <> 3 != 4 ...
    Until the camel can pass though the eye of the needle.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •