Errors in bash with if statements

Hello everyone,
I got this type of error when programming in bash
new.bat: 16: cannot create : Directory nonexistent
$bool
new.bat: 37: Syntax error: "then" unexpected (expecting "fi")
Does anyone know why?
Here is my code

#!bin/bash
#function helps(){
#echo "$ compile -o filename -clean -backup - archive -help cfilenames"
#echo "-o Filename : the mandatory argument that indicates the compiled executable name."
#echo "-clean : remove all.o files in backup"
#echo "-backup : copy all files in Backup folder from C"
#echo "-archive : tar the Source directory and move the tar to Backup folder"
#echo "-help : display this help information"
#}
s1='h'
s2='clean'
s3='backup'
s4='archive'
bool=''
echo $1 >File.txt
grep "o " File.txt > $bool
echo '$bool'
if [ bool = '' ];
then
rm -f -r File.txt
echo "Argument -o is mandatory"
echo "help menu"
echo "$ compile -o filename -clean -backup - archive -help cfilenames"
echo "-o Filename : the mandatory argument that indicates the compiled executable name."
echo "-clean : remove all.o files in backup"
echo "-backup : copy all files in Backup folder from C"
echo "-archive : tar the Source directory and move the tar to Backup folder"
echo "-help : display this help information"
fi
if [ bool != ''];
then
rm -f -r File.txt
echo "write the path of your C file please."
read filename
gcc filename $1
if[$s1=$1 -o $s1=$s2 -o $s1=$3 -o $s1=$4 -o $s1=$5];
then
echo "help menu"
echo "$ compile -o filename -clean -backup - archive -help cfilenames"
echo "-o Filename : the mandatory argument that indicates the compiled executable name."
echo "-clean : remove all.o files in backup"
echo "-backup : copy all files in Backup folder from C"
echo "-archive : tar the Source directory and move the tar to Backup folder"
echo "-help : display this help information"
fi
if[$s2=$1 -o $s2=$s2 -o $s2=$3 -o $s2=$4 -o $s2=$5];
then
cd ~/Projects/Store/Backup
rm -f -r *.o
fi
if[$s3=$1 -o $s3=$2 -o $s3=$3 -o $s3=$4 -o $s3=$5 -o $s3=$6];
then
cd ~/Projects/Store/Build1/Source/C
mv -f *.o *.h ~/Projects/Store/Backup
fi
if[$s4=$1 -o $s4=$2 -o $s4=$3 -o $s4=$4 -o $s4=$5 -o $s4=$6];
then
cd ~/Projects/Store/Build1/Source
tar -cvvf Source.tar Source/
fi
fi

Either one of my contact lenses fell out, or that's a very small font!

Please repost with code-tags.

echo '$bool'  should be echo "$bool"
if [ bool = '' ]; should be  if [ -z $bool ];
if[$s1=$1 -o $s1=$s2 -o $s1=$3 -o $s1=$4 -o $s1=$5];  should be if [ $s1 -eq $1 -o $s1 -eq $s2 -o $s1 -eq $3 -o $s1 -eq $4 -o $s1 -eq $5 ]; 

To keep the forums high quality for all users, please take the time to format your posts correctly.

  1. Use Code Tags when you post any code or data samples so others can easily read your code.
    You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags and by hand.)
  2. Avoid adding color or different fonts and font size to your posts.
    Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.
  3. Be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
Reply With Quote

Remove the semicolon after the if statement that is not require unlese you are keeping your then in the same statement -- remove all semicolon from the end of if statement and try

When you put a semicolon at the end of if --it mean the statement is complete there and - so in the next line when you say ' then' it will be like then with out if and hence the error

The script is actually littered with errors.

bool=''
echo $1 >File.txt
grep "o " File.txt > $bool
echo '$bool'
if [ bool = '' ];
then
rm -f -r File.txt
echo "Argument -o is mandatory"
echo "help menu"
echo "$ compile �o filename �clean �backup � archive -help cfilenames"
echo "-o Filename : the mandatory argument that indicates the compiled executable name."
echo "-clean : remove all.o files in backup"
echo "-backup : copy all files in Backup folder from C"
echo "-archive : tar the Source directory and move the tar to Backup folder"
echo "-help : display this help information"
fi
if [ bool != ''];
then
rm -f -r File.txt
echo "write the path of your C file please."
read filename
gcc filename $1
if[$s1=$1 -o $s1=$s2 -o $s1=$3 -o $s1=$4 -o $s1=$5];

This part alone has a bunch.

There is nothing wrong with the semi-colons.