1

I feel really guilty for asking this. I am a beginner with bash and I wanted to make a simple script.

I have a syntax error, simplified the script to the maximum and still get the syntax error.

Would you guys be kind enough to guide me?

#!/bin/bash
while true
do
    while read IP;
    do
        if true ; 
        then
            echo "$IP";
        fi
    done < /var/www/html/people.txt
    sleep 1
done

Gives me following error :

line 10: syntax error near unexpected token `done'
line 10: `    done < /var/www/html/people.txt

It seems to work on my friend's server but not mine.

EDIT : I simply had no idea I had to make a new line after the final done.

Ulu Ozanbe
  • 11
  • 2
  • You almost certainly have DOS newlines in this. Use `dos2unix`, or open it in vim and run `:set fileformat=unix`. – Charles Duffy Sep 16 '16 at 17:43
  • Can you try running this script from command line like so? `bash yourscript.sh`. What version of bash does your friend have and what version do you have? You can find version by typing `bash --version`? Following up on Charles's comment - type `dos2unix yourscript.sh` and try running the script again – zedfoxus Sep 16 '16 at 17:45
  • `bash -x yourscript`, better -- that way it logs each command. But if the syntax error happens at parse time for the loop, it may not run anything. – Charles Duffy Sep 16 '16 at 17:45
  • @zedfoxus, I try to look for the best in people, and thus hope that someone I don't know isn't putting a `.sh` extension on a bash script (which, as indicated by its shebang, is *not* built for invocation with POSIX sh, making the extension misleading, and moreover is an executable, which by convention on UNIX doesn't have an extension -- one doesn't run `ls.elf`, after all). – Charles Duffy Sep 16 '16 at 17:46
  • Good point, @CharlesDuffy. Thank you. – zedfoxus Sep 16 '16 at 17:47
  • Thanks for you help guys, I found my answer :) – Ulu Ozanbe Sep 16 '16 at 18:23

0 Answers0