#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Posts
    6
    Rep Power
    0

    Constraint in while loop


    Hi,

    I have the following code
    Code:
    USER=`id|sed -n 's/^[^(]*(\([^)]*\)).*/\1/p'`
    while :
            do
            tput cup 9  1 ; echo $CL
            tput cup 7  1 ; echo "Proceed with daily clean up operation (Y/N): _ \c"
            tput cup 7 46 ; read _Proceed
            ##
            ## Validate reply
            ##
            _Proceed="$(echo "$_Proceed" | tr "[:lower:]" "[:upper:]")"
    
            if [ "$_Proceed" != "Y" -a "$_Proceed" != "N" ] ; then
            tput cup 9 1 ; echo " ERROR: Proceed reply ${_Proceed} is invalid\c"
    
      Pause ; continue
    
                      ##If yes proceed, follow
    
                      if [ "$_proceed" = "Y" ]; then
    echo $ENTER THE FILE NAME TO MAIL
    read F
    #/etc/outils_root/admin_root/send_mail_pj.ksh -s "[PHALANGER_FILES/$USER/`uname -n`]" -f $F -d $DESTINATAIRE
    fi
    
      ## If no proceeed, exit routine
    
      ##
    
      if [ "$_Proceed" = "N" ] ; then return ; fi
    
    
      break
    
      done
    
      fi
    while executing this i have a error
    ./mail.sh: syntax error at line 27 : `done' unexpected
    i belive some loop issue but i'm unable to trace it please help me on this.

    thanks for the help

    Regards
    Thelak
  2. #2
  3. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,897
    Rep Power
    3886
    What scripting language are you using?

    In bash (for example), a "while" loop is terminated with a "done" statement: see here.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Posts
    6
    Rep Power
    0
    Originally Posted by ishnid
    What scripting language are you using?

    In bash (for example), a "while" loop is terminated with a "done" statement: see here.
    Hi
    i missed out the whole query sorry for that now i modified
    it
    it's having the done but its expecting something
    Thanks for understanding.

    Regards
    Thelak
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,436
    Rep Power
    1688

    typo


    I generally don't put a colon after a while (as far as I am aware it is redundant).

    Code:
    _Proceed="$(echo "$_Proceed" | tr "[:lower:]" "[:upper:]")"
    is probably not doing what you think due to the usage of the quotes, try:
    Code:
    _Proceed=$(echo "$_Proceed" | tr "[:lower:]" "[:upper:]" | cut -c 1)
    which will also, as a benefit, only return the first character, so "no" or "yes", etc., can be used as valid input

    If you are using bash, then your echo commands that use \c will need the -e parameter.

    But your main issue is that you have mis-placed the loop/conditional terminators. Without the actual code, what you have is:
    Code:
    while
      if
        if
        fi
      fi
      fi
    done
    fi
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc

IMN logo majestic logo threadwatch logo seochat tools logo