Find the answer to your Linux question:
Results 1 to 5 of 5
Hey, I am very much new to shell scripting. Well I build one script in which i need if then else loop for Yes Or No options. Taking input of ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux User infoshirish's Avatar
    Join Date
    May 2007
    Location
    Pune, India
    Posts
    397

    Red face If then Else if....


    Hey,
    I am very much new to shell scripting. Well I build one script in which i need if then else loop for Yes Or No options. Taking input of Yes and No from keyboard, It is exactly like this:-
    If option=Yes
    Execute some statements
    Else if option=No
    Execute some statements


    But execute, it gives me Syntax error or command not found. Please tell me what should be exact syntax. I tried all permutations / combinations.
    Regards,

    who |grep -i blonde |
    date; cd~; unzip; touch;
    strip; finger; mount; gasp;
    yes; uptime; umount;
    sleep

    Newbie clicks
    http://www.linuxforums.org/forum/lin...ead-first.html

  2. #2
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,729
    Code:
    #!/bin/bash
    
    echo "Enter Option"
    read option
    if [ "$option" = "Yes" ]; then
            echo "its Yes"
      
        elif [ "$option" = "No" ]; then
                   echo "its No"
        else
                   echo "its neither Yes nor No"
    fi
    It is amazing what you can accomplish if you do not care who gets the credit.
    New Users: Read This First

  3. #3
    Linux Newbie Sangal-Arun's Avatar
    Join Date
    May 2006
    Location
    Gurgaon, India + Denver Colorado USA
    Posts
    101

    Wink

    Just fyi..
    If then elsif else fi ... is not a loop. it's a statement.
    Brgds,

    ARUN SANGAL
    SCM: 1- 720 251 9962
    Email: sangal.ak04@gmail.com
    Email: sangal_ak04@yahoo.com

  4. $spacer_open
    $spacer_close
  5. #4
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,729
    Quote Originally Posted by Sangal-Arun
    If then elsif else fi ... is not a loop. it's a statement.
    Yes. Its not a loop and I did that intentionally. Let Infoshirish do some research himself and that will help him more.
    It is amazing what you can accomplish if you do not care who gets the credit.
    New Users: Read This First

  6. #5
    Linux User infoshirish's Avatar
    Join Date
    May 2007
    Location
    Pune, India
    Posts
    397
    Hey,
    I did some RnD and i got what i wanted, script working fine now. Anyways thanks for your greate help.
    Regards,

    who |grep -i blonde |
    date; cd~; unzip; touch;
    strip; finger; mount; gasp;
    yes; uptime; umount;
    sleep

    Newbie clicks
    http://www.linuxforums.org/forum/lin...ead-first.html

Posting Permissions

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