Find the answer to your Linux question:
Results 1 to 4 of 4
I cam across this notation in an online bash tutorial bit I fail to understand how it can make a script simpler by allowing you to not type the same ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2004
    Posts
    42

    cat << EOF


    I cam across this notation in an online bash tutorial bit I fail to understand how it can make a script simpler by allowing you to not type the same command over and over. Can anyone explain this notation in simple terms please?

    Cheers

  2. #2
    Linux Guru
    Join Date
    Mar 2003
    Location
    Wisconsin
    Posts
    1,907
    As an example, rather then typing

    echo "Hello"
    echo "How are you today"
    echo "That good, hey"

    You can simply type

    echo << EOF
    Hello
    How are you today
    That good, hey
    EOF

    This crude example is trivial, but as always, the implications are far reaching. This method of displaying information is heavily used in Perl-CGI scripts to generate HTML.

    Jeremy
    Registered Linux user #346571
    "All The Dude ever wanted was his rug back" - The Dude

  3. #3
    Just Joined!
    Join Date
    Oct 2010
    Posts
    1
    Here is another example:

    Code:
    #!/bin/bash
    
    some_function()
    {
       echo do something with variable $PARAM1 $PARAM2
    }
    
    cat <<EOF | while read PARAM1 PARAM2; do some_function; done
    data1a data2a
    data1b data2b
    data1c data2c
    EOF

  4. #4
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    It is also helpful if you have a command that takes input via its standard input stream, but the input you want to give it was calculated in your script somehow:
    Code:
    ...
    long calculation that eventually defines $var
    ...
    
    my_command <<EOI
    $var
    EOI

Posting Permissions

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