Shell Script Error Expecting "Do"

shell script error expecting do

I suspect line endings.

Try:

hexdump -C yourscript.sh 

And look for 0d 0a sequences. You can strip \r (0d) with the tr command:

cat yourscript.sh | tr -d '\r' >> yournewscript.sh

for loop shell script syntax error: unexpected word (expecting do )

Found a ^M when i opened it in vi editor. It helped me to solve it.

so it was some thing like this when i opened it in vi editor

for file in $PRO
do^M
echo $file
done^M

Later used the dos2unix command by referring to computerhope.com/unix/dos2unix.htm

Syntax error: end of file unexpected (expecting do )

If it should be an infinite loop try

while [ 1 = 1 ]
do
nohup php retrieve4.php 1 > /dev/null 2>&1 &
nohup php retrieve4.php 2 > /dev/null 2>&1 &
done

EDIT

while [ 1 ] 
do
echo 'test'
done

This is running perfectly well on my setup. Therefore I'd expect your method of running the script is wrong

You could also try something like this:

while true ; do php my_script.php ; done > /dev/null

Shell script for loop error: Syntax error: word unexpected (expecting do )

It turned out to be extraneous characters after all. I ran the following command and the script started working afterwards. Sorry for the confusion, and thanks for the help everyone!

tr -cd '\11\12\15\40-\176' < file-with-binary-chars > clean-file

error: unexpected end of file (expecting do ) for shell script in Dockerfile

Remove the square brackets [], and use ; at the end of lines because docker joins lines when sees your \'s, so the commands get melt.

This is working for me:

RUN cat .env | while read LINE ;\
do \
envName=$(echo "$LINE" | grep -o "^[^\=]*"); \
echo "PassEnv $envName" >> httpd.conf ;\
done


Related Topics



Leave a reply



Submit