What does this `cat` statement do?











up vote
1
down vote

favorite
1












I'm trying to figure out what this statement in a Bash file does. I think it combines stdout, stderr and output it to the file $log is pointing to and append the multiline string to it. Is it right?



cat << EOF >> $log 2>&1   
the quick brown
fox jumps
EOF









share|improve this question




















  • 2




    Type man bash, and read up on it. None if the stuff after cat is an input to cat, it is interpreted by bash before cat is started. On Unix much stuff is done by the shell not the commands. This makes things simpler to write and more consistent to use.
    – ctrl-alt-delor
    Aug 30 '14 at 16:11










  • it does the same thing every cat statement does - it concatenates stdin to stdout.
    – mikeserv
    Aug 30 '14 at 17:58










  • The title is undescriptive, but I can't think of a good summary either, mostly because it's unclear what exactly about the command is confusing. Maybe something like "What does a pair of less-than-signs mean in bash?" would work.
    – Anko
    Aug 30 '14 at 23:34















up vote
1
down vote

favorite
1












I'm trying to figure out what this statement in a Bash file does. I think it combines stdout, stderr and output it to the file $log is pointing to and append the multiline string to it. Is it right?



cat << EOF >> $log 2>&1   
the quick brown
fox jumps
EOF









share|improve this question




















  • 2




    Type man bash, and read up on it. None if the stuff after cat is an input to cat, it is interpreted by bash before cat is started. On Unix much stuff is done by the shell not the commands. This makes things simpler to write and more consistent to use.
    – ctrl-alt-delor
    Aug 30 '14 at 16:11










  • it does the same thing every cat statement does - it concatenates stdin to stdout.
    – mikeserv
    Aug 30 '14 at 17:58










  • The title is undescriptive, but I can't think of a good summary either, mostly because it's unclear what exactly about the command is confusing. Maybe something like "What does a pair of less-than-signs mean in bash?" would work.
    – Anko
    Aug 30 '14 at 23:34













up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






1





I'm trying to figure out what this statement in a Bash file does. I think it combines stdout, stderr and output it to the file $log is pointing to and append the multiline string to it. Is it right?



cat << EOF >> $log 2>&1   
the quick brown
fox jumps
EOF









share|improve this question















I'm trying to figure out what this statement in a Bash file does. I think it combines stdout, stderr and output it to the file $log is pointing to and append the multiline string to it. Is it right?



cat << EOF >> $log 2>&1   
the quick brown
fox jumps
EOF






shell-script cat here-document






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 at 20:00









Rui F Ribeiro

38.3k1475126




38.3k1475126










asked Aug 30 '14 at 15:26









mikeymike

92




92








  • 2




    Type man bash, and read up on it. None if the stuff after cat is an input to cat, it is interpreted by bash before cat is started. On Unix much stuff is done by the shell not the commands. This makes things simpler to write and more consistent to use.
    – ctrl-alt-delor
    Aug 30 '14 at 16:11










  • it does the same thing every cat statement does - it concatenates stdin to stdout.
    – mikeserv
    Aug 30 '14 at 17:58










  • The title is undescriptive, but I can't think of a good summary either, mostly because it's unclear what exactly about the command is confusing. Maybe something like "What does a pair of less-than-signs mean in bash?" would work.
    – Anko
    Aug 30 '14 at 23:34














  • 2




    Type man bash, and read up on it. None if the stuff after cat is an input to cat, it is interpreted by bash before cat is started. On Unix much stuff is done by the shell not the commands. This makes things simpler to write and more consistent to use.
    – ctrl-alt-delor
    Aug 30 '14 at 16:11










  • it does the same thing every cat statement does - it concatenates stdin to stdout.
    – mikeserv
    Aug 30 '14 at 17:58










  • The title is undescriptive, but I can't think of a good summary either, mostly because it's unclear what exactly about the command is confusing. Maybe something like "What does a pair of less-than-signs mean in bash?" would work.
    – Anko
    Aug 30 '14 at 23:34








2




2




Type man bash, and read up on it. None if the stuff after cat is an input to cat, it is interpreted by bash before cat is started. On Unix much stuff is done by the shell not the commands. This makes things simpler to write and more consistent to use.
– ctrl-alt-delor
Aug 30 '14 at 16:11




Type man bash, and read up on it. None if the stuff after cat is an input to cat, it is interpreted by bash before cat is started. On Unix much stuff is done by the shell not the commands. This makes things simpler to write and more consistent to use.
– ctrl-alt-delor
Aug 30 '14 at 16:11












it does the same thing every cat statement does - it concatenates stdin to stdout.
– mikeserv
Aug 30 '14 at 17:58




it does the same thing every cat statement does - it concatenates stdin to stdout.
– mikeserv
Aug 30 '14 at 17:58












The title is undescriptive, but I can't think of a good summary either, mostly because it's unclear what exactly about the command is confusing. Maybe something like "What does a pair of less-than-signs mean in bash?" would work.
– Anko
Aug 30 '14 at 23:34




The title is undescriptive, but I can't think of a good summary either, mostly because it's unclear what exactly about the command is confusing. Maybe something like "What does a pair of less-than-signs mean in bash?" would work.
– Anko
Aug 30 '14 at 23:34










1 Answer
1






active

oldest

votes

















up vote
7
down vote













First, cat must be written lowercase. This command statement uses the concept of here documents.



The first part cat << EOF means that stdin (standard input) of the command comes afterwards. All that comes after the first line until the word EOF is the standard input to the command cat. Or from the documentation:




This type of redirection instructs the shell to read input from the
current source until a line containing only delimiter (in your case it's EOF) (with no
trailing blanks) is seen. All of the lines read up to that point
are then used as the standard input for a command.




The second part of the command >> $log 2>&1 means that the output of stdout and stderr both, should be appended to a file whose name is in the variable $log.



Conclusion: A file like this is now generated:



the quick brown
fox jumps





share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "106"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f152931%2fwhat-does-this-cat-statement-do%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    7
    down vote













    First, cat must be written lowercase. This command statement uses the concept of here documents.



    The first part cat << EOF means that stdin (standard input) of the command comes afterwards. All that comes after the first line until the word EOF is the standard input to the command cat. Or from the documentation:




    This type of redirection instructs the shell to read input from the
    current source until a line containing only delimiter (in your case it's EOF) (with no
    trailing blanks) is seen. All of the lines read up to that point
    are then used as the standard input for a command.




    The second part of the command >> $log 2>&1 means that the output of stdout and stderr both, should be appended to a file whose name is in the variable $log.



    Conclusion: A file like this is now generated:



    the quick brown
    fox jumps





    share|improve this answer



























      up vote
      7
      down vote













      First, cat must be written lowercase. This command statement uses the concept of here documents.



      The first part cat << EOF means that stdin (standard input) of the command comes afterwards. All that comes after the first line until the word EOF is the standard input to the command cat. Or from the documentation:




      This type of redirection instructs the shell to read input from the
      current source until a line containing only delimiter (in your case it's EOF) (with no
      trailing blanks) is seen. All of the lines read up to that point
      are then used as the standard input for a command.




      The second part of the command >> $log 2>&1 means that the output of stdout and stderr both, should be appended to a file whose name is in the variable $log.



      Conclusion: A file like this is now generated:



      the quick brown
      fox jumps





      share|improve this answer

























        up vote
        7
        down vote










        up vote
        7
        down vote









        First, cat must be written lowercase. This command statement uses the concept of here documents.



        The first part cat << EOF means that stdin (standard input) of the command comes afterwards. All that comes after the first line until the word EOF is the standard input to the command cat. Or from the documentation:




        This type of redirection instructs the shell to read input from the
        current source until a line containing only delimiter (in your case it's EOF) (with no
        trailing blanks) is seen. All of the lines read up to that point
        are then used as the standard input for a command.




        The second part of the command >> $log 2>&1 means that the output of stdout and stderr both, should be appended to a file whose name is in the variable $log.



        Conclusion: A file like this is now generated:



        the quick brown
        fox jumps





        share|improve this answer














        First, cat must be written lowercase. This command statement uses the concept of here documents.



        The first part cat << EOF means that stdin (standard input) of the command comes afterwards. All that comes after the first line until the word EOF is the standard input to the command cat. Or from the documentation:




        This type of redirection instructs the shell to read input from the
        current source until a line containing only delimiter (in your case it's EOF) (with no
        trailing blanks) is seen. All of the lines read up to that point
        are then used as the standard input for a command.




        The second part of the command >> $log 2>&1 means that the output of stdout and stderr both, should be appended to a file whose name is in the variable $log.



        Conclusion: A file like this is now generated:



        the quick brown
        fox jumps






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Aug 30 '14 at 16:13









        ctrl-alt-delor

        10.2k41955




        10.2k41955










        answered Aug 30 '14 at 16:07









        chaos

        34.8k773115




        34.8k773115






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f152931%2fwhat-does-this-cat-statement-do%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Accessing regular linux commands in Huawei's Dopra Linux

            Can't connect RFCOMM socket: Host is down

            Kernel panic - not syncing: Fatal Exception in Interrupt