LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-11-2009, 12:28 AM   #1
xskycamefalling
Member
 
Registered: May 2009
Posts: 43

Rep: Reputation: 15
bash scripting problem with nested if statements in while loop error


ok so im getting a syntax error on line 74 the 2nd to last fi the code is as follows

Code:
#!/bin/sh

echo "enter the sentance or word you would like to have translated"
read "line"
y="y"
n="n"
echo "Would you like to have this sentance translated to pig laton?"
echo "y or n"
read "answer"
if [ "$answer" = "$y" ]
then
    pig=`echo "$line" | pig`
    echo "$pig"
else
    if [ "$answer" = "$n" ]
    then
        echo "would you like to have this sentance translated to morse code?"
        echo "y or n"
        read "answer"
            if [ "$answer" = "$y" ]
            then
                morse=`echo "$line" | morse -s`
                echo "$morse"
            else
                if [ "$answer" = "$n" ]
                then
                    echo "fine then"
                fi

            fi
    fi
fi

while [ "$answer1" != "$n" ]
do
    echo "is there anything else you would like to have translated?"
    echo "y or n"
    read "answer1"
    if [ "$answer1" = "$y" ]
    then
        echo "enter the sentance or word you would like to have translated"
        read "line"
    else
        if [ "$answer1" = "$n" ]
        then
            echo "FINE THEN GOODBYE"
        fi
    fi
echo "would you like to have this sentance translated to pig laton?"
echo " y or n"
read "answer"
if [ "$answer" = "$y" ]
then
    pig=`echo "$line" | pig`
     echo "$pig"
else
    if [ "$answer" = "$n" ]
        echo "Would you like to have this sentance translated to morse code?"
        echo "y or n"
        read "answer"
        if [ "$answer" = "$y" ]
        then
            morse=`echo "$line" | morse -s`
            echo "$morse"
        else
            if [ "$answer" = "$n" ]
            then
                echo "ok"
            else
            sleep 5

            fi
        fi
    fi
fi
done
any help is appreciated
 
Old 05-11-2009, 12:59 AM   #2
Dralnu
Member
 
Registered: Jul 2005
Posts: 335

Rep: Reputation: Disabled
First, I would change /bin/sh to /bin/bash. This way you should be sure that everything will work as expected incase this script it run on a diffrent system that has /bin/sh linked to another shell, or actually contains the old Bourne Shell.

Secondly, you're missing a then after line 57
 
Old 05-11-2009, 03:08 AM   #3
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Quote:
Originally Posted by Dralnu View Post
First, I would change /bin/sh to /bin/bash. This way you should be sure that everything will work as expected incase this script it run on a diffrent system that has /bin/sh linked to another shell, or actually contains the old Bourne Shell.
I disagree. /bin/sh must be linked to bash-compatible shell, and in any system in the past decade it is definitely NOT the old Bourne shell.

I think it is correct to use /bin/sh instead of /bin/bash as TODAY it is more likely that bash may not be installed and instead /bin/sh is linked to say ksh or other bash-compatible. So it's better to use /bin/sh IMO.
 
Old 05-11-2009, 01:02 PM   #4
Dralnu
Member
 
Registered: Jul 2005
Posts: 335

Rep: Reputation: Disabled
Quote:
Originally Posted by H_TeXMeX_H View Post
I disagree. /bin/sh must be linked to bash-compatible shell, and in any system in the past decade it is definitely NOT the old Bourne shell.

I think it is correct to use /bin/sh instead of /bin/bash as TODAY it is more likely that bash may not be installed and instead /bin/sh is linked to say ksh or other bash-compatible. So it's better to use /bin/sh IMO.
Do you mean POSIX-compatable shell?
 
Old 05-11-2009, 03:14 PM   #5
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Do you know of any distro today that still uses the old Bourne shell ? I don't. But I know some distros where bash is not necessary and is replaced by ksh, but the symlink from /bin/sh is still there.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[bash] if statements in a loop MarkGM Programming 3 04-02-2009 08:12 PM
bash scripting: loop over a file, replacing two decimal numbers frankie_DJ Programming 2 04-30-2007 04:04 PM
nested loop in Perl help needed Grafbak Programming 9 12-19-2006 10:28 AM
Nested-double loop error Harry Seldon Programming 3 05-06-2006 05:15 PM
Do/while loop and if statements not functioning properly w/ array... ohfaney Programming 5 05-02-2006 02:22 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration