In my bash script I'm getting an error:
./buildscriptbuild.sh: line 20: syntax error near unexpected token 'fi'
I have tested the below bash script in my local system. Can anyone help me in this regard. Thanks in advance.
#!/bin/sh
cd /home/ec2-user/inoutserver
if git pull origin development; then
if npm install; then
if grunt build --force; then
echo "build success"
else
if sudo cp -r dist/* /home/ec2-user/testfolder; then
echo "deployment success!"
fi
else
echo "deployment failed"
fi
else
echo "build failed"
fi
else
echo "npm install failed"
fi
if sudo cp -r dist/* /home/ec2-user/testfolder; then
if block... where's theelse
vs thefi
?if
...fi
...else
sequence that really shouldn't be that way. The mistake would be a lot more obvious if you fixed the indentation, so that correspondingif
,else
, andfi
keywords were at the same indentation level. Also, it'd be a lot clearer to rewrite this with the error conditions first, as anif ! step1command; then echo "step 1 error"; elif ! step2command; then echo "step 2 error"; elif ! step3command;...
See this.