Evening All (or morning for some),
Could anyone have a look at the below and advise where i've going wrong with the syntax as i keep getting the below error while trying to run.
Any help would be really apprecaited.
./testout: line 13: syntax error near unexpected token `else'
#!/bin/sh
Type=p
Con=c
Pl=t
if (( $1 == 'a' )); then
if (( $Type == 'p' )); then
if (( $Con == 'c' )) || (( $Con == 'p' )); then
if (( $Con == 'p' )); then
Da='1'
echo "Migrated"
else
Da='1'
fi
if (( $Pl != "null" ));then
DT='1'
fi
fi
fi
fi
if ($stat == 'a')
{
if (($Type=='p')|| ($Type=='b') || ($Type=='c') || ($Type=='d'))
$Da = '1'
if condition requires space between two equal to symbol ie ==
A complete if - else needs to be closed by having fi at last but I see at least 3 pairs of if - else here which are not properly closed, kindly do close them properly.
I am afraid what you have posted is not shell syntax.
Here's an interpretation of what you have posted in shell syntax without any effort in correcting the logic flow of it:
if [ "$stat" = a ]
then
if [ "$Type" = p ] || [ "$Type" = b ] || [ "$Type" = c ] || [ "$Type" = d ]
then
if [ "$Con" = c ] || [ "$Con" = p ]
then
if [ "$Con" = p ]
then
Da=1
echo "Migrated"
else
Da=1
fi
if [ -n "$Pl" ]
then
DT=1
fi
fi
if [ "$Mig" = "not migrated 1" ]
then
echo "not migrated 1"
else
DAR=1
echo "$DAR Decode 3"
fi
else
DAR=1
echo "$DAR Decode 4"
fi
fi
Watch out for extra spaces between assignments.
Watch out for extra $ symbol when doing assignments. if is not with curly bracket nor does it work like C or C++, the construct is
if [ ... ]
then
...
else
...
fi
There must be a space between expression [ expression ]
Double quote the variable "$name" when evaluating with single [ ] .