Quote:
Originally Posted by PasBern
I have removed the semi-colons in line 5 and 10 ("$@"; do
|
The one in line 5 (before the "do") is needed and it being missing is the reason of your error message, the ones in lines 9 and 11 (at the end of the line) are
not, they already have a newline after it.
But the keywords "do", "done" "then", "else", "fi" etc always need to be the first WORD on a line,
or after a ; to concatenate two lines into one.
Quote:
Now Bash complains about an unexpected end of file.
|
That normally means it is missing some (reserved) keyword somewhere, in this case it didn't see the "do" in line 5. From the man page of bash
Quote:
for name [ [ in [ word ... ] ] ; ] do list ; done
|
so the (first) ; can only be omitted when NO "in" keyword is used.
Any ; can always be replaced by a newline, so when "do" or "done" are on its own lines, the preceding ; isn't needed anymore. like
Code:
for name [ in word ... ]
do list
done
Another quote from the man page
Quote:
Reserved words are words that have a special meaning to the shell. The following words are recognized as reserved when unquoted and either the first word of a simple command (see SHELL GRAMMAR below) or the third word of a case or for command:
! case do done elif else esac fi for function if in select then until while { } time [[ ]]
|
So in a "for" the "do" keyword is only recognized when the
third word, but there already is an "in" there.
PS: I always put the "do" and the "done" on the same indent level in those cases, so you can see the enclosed block.