SeanBarton
asked on
Bourne Shellscript
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
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
You could even return a value with the exit and use that return value for further actions.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hmmm ... scratching my hairless head ...
To exit a script just call "exit"
======
Werner