Re: Bash, cat and EOF problem
Dave Thayer wrote:
> On Thu, Mar 02, 2006 at 02:41:08PM +0800, LUK ShunTim wrote:
>
>
>><script1>
>>cat <<EOF >>outfile
>>Some words
>>EOF
>></script1>
>>
>>works but when it is embedded inside an if-then-fi construct like,
>>
>><script2>
>>AAA=""
>>if [ -z "$AAA" ]; then
>> cat <<EOF >>outfile
>> Some words
>> EOF
>>fi
>></script2>
>>
>>it fails with error message
>>"script2: line 7: syntax error: unexpected end of file"
>>
>>What have I missed?
>
>
> It's not the if-then-fi causing your problem, but the indentation within.
> Lose the leading spaces in the here text (unless you want your outfile to
> contain " Some words" rather than "Some words") and the limit string
> ("EOF").
>
> See <http://www.tldp.org/LDP/abs/html/here-docs.html#INDENTEDLS>
>
> HTH
>
> dt
>
Hello Dave and Andrew,
Thanks very much for the useful information.
Regards,
ST
--
Reply to: