Find the answer to your Linux question:
Results 1 to 2 of 2

Thread: bash nested EOF

Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #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


    outer_command <<OUTER_EOF
    inner_command <<INNER_EOF
    start of inner_script contents
    end of inner_script contents

  2. #2
    Linux User
    Join Date
    Nov 2008
    Tokyo, Japan
    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 this
    cat <<-__SUB_COMMAND0__
    Executed within level 0
    bash <<-__LEVEL1__
    cat <<-__SUB_COMMAND1__
    Executed within level 1
    bash <<-__LEVEL2__
    cat <<-__SUB_COMMAND2__
    Executed within level 2
    What 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.

    However, as you can see, this quickly turns into spaghetti code and is very difficult to read and debug.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts