What does this `cat` statement do?
up vote
1
down vote
favorite
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
add a comment |
up vote
1
down vote
favorite
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
2
Type man bash, and read up on it. None if the stuff aftercat
is an input tocat
, it is interpreted by bash beforecat
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 everycat
statement does - it concatenatesstdin
tostdout
.
– 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
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
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
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
shell-script cat here-document
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 aftercat
is an input tocat
, it is interpreted by bash beforecat
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 everycat
statement does - it concatenatesstdin
tostdout
.
– 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
add a comment |
2
Type man bash, and read up on it. None if the stuff aftercat
is an input tocat
, it is interpreted by bash beforecat
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 everycat
statement does - it concatenatesstdin
tostdout
.
– 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
add a comment |
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
add a comment |
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
add a comment |
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
add a comment |
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
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
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
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
2
Type man bash, and read up on it. None if the stuff after
cat
is an input tocat
, it is interpreted by bash beforecat
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 concatenatesstdin
tostdout
.– 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