Results 1 to 2 of 2
I need to write a script with nested EOF's to avoid generating potentially very large numbers of intermediate files and cannot work out how to do this, rough code follows; ...
- 03-09-2011 #1Just Joined!
- Join Date
- Mar 2011
- Posts
- 1
bash nested EOF
I need to write a script with nested EOF's to avoid generating potentially very large numbers of intermediate files and cannot work out how to do this, rough code follows; any ideas greatly appreciated
#!/bin/sh
outer_command <<OUTER_EOF
#!/bin/sh
inner_command <<INNER_EOF
start of inner_script contents
.
.
.
end of inner_script contents
INNER_EOF
OUTER_EOF
- 03-10-2011 #2Linux Newbie
- Join Date
- Nov 2008
- Location
- Tokyo, Japan
- Posts
- 243
First, my opinion is, if you need nested "Here Files", you are almost certainly going about solving your problem the wrong way. Or if you are sure this is the ONLY way to solve the problem, you are better of NOT using bash. Try Perl or Python instead.
However, to answer your question, I would do it like thisWhat this does is creates a child bash process with the input of the child process coming from the "Here File". Once you have established the bash sub-process, you can "cat" information to sub-sub-processes like grep or whatever.Code:#!/bin/bash cat <<-__SUB_COMMAND0__ Executed within level 0 __SUB_COMMAND0__ bash <<-__LEVEL1__ cat <<-__SUB_COMMAND1__ Executed within level 1 __SUB_COMMAND1__ bash <<-__LEVEL2__ cat <<-__SUB_COMMAND2__ Executed within level 2 __SUB_COMMAND2__ __LEVEL2__ __LEVEL1__
However, as you can see, this quickly turns into spaghetti code and is very difficult to read and debug.


Reply With Quote