Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a here document in a loop? [duplicate]

Tags:

bash

shell

This works:

name="test.txt"

yap -q << % > $name
  [experiment_yap],
  exp1_min(brother,2).
%

This does not:

for i in 01 02 03 04 05
do
  name="test.txt"

  yap -q << % > $name
    [experiment_yap],
    exp1_min(brother,2).
  %
done

I receive line 19: syntax error: unexpected end of file

like image 954
S0rin Avatar asked Dec 25 '22 09:12

S0rin


1 Answers

It's not being in a loop that's significant here. bash doesn't really know or care about indentation -- to recognize the end of the heredoc the terminating string must be at the beginning of the line, which makes your loop look like:

for i in 01 02 03 04 05
do
  name="test.txt"

  yap -q << % > $name
    [experiment_yap],
    exp1_min(brother,2).
%
done
like image 181
FatalError Avatar answered Dec 31 '22 10:12

FatalError