We help IT Professionals succeed at work.
Get Started

Bourne Shellscript

SeanBarton
SeanBarton asked
on
508 Views
Last Modified: 2010-04-21
this is a bourne shellscript to  start an at command. can you please tell me how to make the program exit?
 on a few occasions i need to exit the script without it running throuhg any more code. there is a comment at one point (when the filename is invalid)

!/bin/sh

if [ $# -eq 2 ]
then

        if [ -f $1 ]
        then
                checksum=1
                optorarg=1
                echo parameter 1 has been verified

        else
                checksum=0
                echo file was not found or was a directory
                echo ------------------------------------------------------------------
                echo would you like to create a new file??
                echo 1 = yes
                echo 0 = no
                echo enter 1 or 0 depending on choice:
                read newfile

                if [ $newfile -eq 1 ]
                then
                        echo program will now create a new file for you
                        echo please remember to save afterwards!!
                        vi $1
                elif [ $newfile -eq 0 ]
                then
                        echo program will now output contents or current folder
                        echo -------------------------------------------------------------------
                        ls -l
                        echo -------------------------------------------------------------------
                        echo please enter the real filename:
                        optorarg=0
                        read option1

                else
                        echo file will now assume you wanted to create a new file
                        optorarg=1
                        vi $option1
                fi
        fi


elif [ $# -eq 0 ]
then
        optorarg=0
        echo no parameter found.
        echo System will now output contents of current directory
        ls -l
        echo please enter parameter 1:
        read option1

                             if [ -f $option1 ]
                then
                        checksum=1
                        echo Thankyou, parameter 1 verified
                else
                        echo Error!: filename invalid!!
                                #how can i exit script here?
                        checksum=0
                fi

        echo Please enter Parameter 2:
        read option2
        echo thankyou...
        checksum=1

else
        echo you have entered one or more than 2 parameters. program will now exit
        checksum=0
fi

if [ $checksum -eq 1 ]
then

        if [ $optorarg -eq 1]
        then
                at -f $1 $2
        else
                at -f $option1 $option2
        fi

else
        echo goodbye
fi



Sean
Comment
Watch Question
Commented:
This problem has been solved!
Unlock 2 Answers and 5 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE