Problem with IF

Hi,
i'm new and i'm coding a little bash for serial check:

#!/bin/sh
#!/bin/bash
serial=$(grep -w "Serial" /proc/cpuinfo)
match="Serial          : 000000000ca1d574"
if [ $serial = $match ] ; then
echo "ok"
else
echo "no"
fi

But if i run sh ./filename.sh i've this error:

./filename.sh: line 11: syntax error: unexpected "fi" (expecting "then")

why? you can help me :frowning:

Thank you.

1 Like

Tried without the space before the ;

if [ "$serial" = "$match" ] ; then

i've tryed to make this change but i get the same error:

filename.sh: line 9: syntax error: unexpected "fi" (expecting "then")

#!/bin/sh
#!/bin/bash
serial=$(grep -w "Serial" /proc/cpuinfo)
match="Serial          : 000000000ca1d574"
if [ "$serial" = "$match" ] ; then
echo "ok"
else
echo "no"
fi

Have you installed bash?
(By default there is only ash from busybox providing sh functionality, but no bash compatibility)

And in any case, you have conflicting double shebang:

Both sh and bash defined ????

ok i've modified the sh:

#!/bin/sh
serial=$(grep -w "Serial" /proc/cpuinfo)
match="Serial          : 000000000ca1d574"
if [ "$serial" = "$match" ] ; then
echo "ok"
else
echo "no"
fi
root@Speezy:~# sh ./filename.sh
./filename.sh: line 8: syntax error: unexpected "fi" (expecting "then")
sed -i -e "s/\r//g" *.sh

https://en.wikipedia.org/wiki/Newline

1 Like

Thank you! :smiley:

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.