Home > shell script > What does this `cat` statement do?

What does this `cat` statement do?

August 30Hits:1
Advertisement

I'm new to Linux and 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  

Answers

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

Related Articles

  • How to wire up a RJ45 socket with cat-5 cable?

    How to wire up a RJ45 socket with cat-5 cable?May 27

    I have some network cable laid, but no sockets as yet. I have done a quick google, and have not had much luck with explanations (other than on the hyphen site). Is there a good, comprehensive guide to how to wire up Ethernet sockets, any advice would

  • cat, pipe, and acroread - why is it failing occasionally?June 5

    in a simple shell script I'm trying to run this command: cat /filelocation/myoutput.PDF | /opt/Adobe/Acrobat7.0/bin/acroread -toPostScript Under most circumstances this is working. Occasionally however, I'm getting an error: lp: standard input is emp

  • Cat 5e cable is dead?July 21

    I just moved into a house with extensive structured wiring cat 5e and RG6 in each room. The Leviton structured media cabinet only had telephone punchdown bridges, so I got a bunch of Leviton Cat5e data/phone boards and started to identify, label and

  • Expect script does not print (cat ) a file on remote serverAugust 6

    I have an expect script which checks if a file exists on a remote server and then tries to print ( using cat) it if it does For some reason the expect script ignores these commands. send "if {[file exists "./abc.test"]} {cat ./abc.txt\r}&qu

  • cat an audio file into the microphone/recording deviceAugust 17

    I need to simulate the process of recording an audio file, using an existing recording. I'm running ubuntu 8.10 and had thought this would be quite simple but it seems now to be rather not so simple. My 'concept' of what I want to do is, $ cat myaudi

  • In UNIX, how can I cat a file located in a different server?August 18

    In UNIX, how can I cat a file located in a different server? Can anybody please help me? Thanks, Prasenjit --------------Solutions------------- With SSH, you can connect to a remote server and use cat remotely: ssh remote_server cat file_name With NF

  • What is the difference between various cable types like Cat 5, Cat 5e and Cat 6?August 21

    I'm just about to move house, so I'm going to have to disconnect and re-wire my network. Pretty much all the devices I have support Gigabit Ethernet. Should I go out and buy some decent network cables (and if so what type) or should I continue using

  • How to protect a keyboard from a cat?

    How to protect a keyboard from a cat?August 22

    Question for any programmer-and cat lover-working from his home office. So many times my keyboard is taken over violently by my two cats who think it's the right place for a nap. And almost every time when they do this I'm was in this precious 100% c

  • How to filter accidental keystrokes caused by my cat?

    How to filter accidental keystrokes caused by my cat? August 22

    Question for any programmer-and cat lover-working from his home office. So many times my keyboard is taken over violently by my two cats who think it's the right place for a nap. And almost every time when they do this I'm was in this precious 100% c

  • Error in the command "cat file | xclip"August 23

    The command works with the user "heo". But I get the error by "$ su another_user; cat file | xclip": No protocol specified Error: Can't open display: :0.0 A superuser has black CLI, no error message or text, with the xauth-command. How

  • Unix cat starting from lineOctober 30

    What is the best way to output from a file starting from a specific line (big number like 70000). Something like: cat --line=70000 <file> --------------Solutions------------- Take a look at tail, more precisecly, it's --lines=+N switch: tail --lines

  • Is there a difference between RJ-45 plugs for Cat-5e and Cat-6?October 30

    While looking around for some plugs to use for running and crimping some bulk Cat-6 cable, I noticed the online sites show RJ-45 plugs for Cat-5e and separate ones for Cat-6. Is there actually any difference between the two? The Cat-6 plugs mention h

  • Can not insert cat-5 cable into iMacNovember 4

    [Note that I am a sysadmin, but this seemed more like a question for superuser than for serverfault]. I have a Apple iMac Intel (Early 2008) and can not insert a Cat-5 cable into the ethernet jack. [I recall that, when we initially set up these sorts

  • Physical difference between Cat 5 and Cat 5e cabling?November 7

    (This isn't really server-related, but it seems more appropriate here than SO or SU.) When we had this house built, we had network cabling run inside the house, or so I'm lead to believe. It's currently hooked up to the phone line. Unfortunately, the

  • SitePoint Podcast #38: A Brain of CatsNovember 27

    Episode 38 of The SitePoint Podcast is now available! This week your hosts are Stephan Segraves (@ssegraves) and Kevin Yank (@sentience). Listen in your Browser Play this episode directly in your browser! Just click the orange "play" button belo

  • Corrupted zip file after using split and cat on LinuxDecember 2

    I had to split this 2.6 GB zip-file in order to send it thru a slow uplink. I did this: split -b 879m BIGFILE.zip This created xaa, xab & xac which I uploaded to the remote server. After the transfer finished I verified each one of these 3 pieces wit

  • Why has 'cat' this strange time behaviour?December 4

    I'm using cat to pipe different files into one big file. The number of different files varies, from two files up to ten, but the total size of all files is always the same (a couple of GB). My problem: Whenever I get to the case where I have a total

  • Get man page out of preformatted cat pageDecember 12

    Is there a way to get the source out of the a preformatted man page? I need to parse the man page sources on different platforms and on one pc there are only cat pages, and I don't want to write 2 scripts for both situations. Greets, Oliver ---------

  • Are there any options to let cat output with color?December 17

    If I want to output a C source code file with syntax highlighting, can I use cat? --------------Solutions------------- A GNU package, source-highlight, seems to do the trick (though isn't using cat -- as John T points out, this isn't possible with ca

  • Display messd up with weird characters in Gentoo after `cat` a binary file

    Display messd up with weird characters in Gentoo after `cat` a binary fileJanuary 4

    I ran cat /etc/localtime to see the contents of /etc/localtime - however it's a binary file, so my console became like this: You may notice the red text in screenshot is "LiveCD"; commands can be executed correctly, but they display in a weird w

Copyright (C) 2018 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.525 s.