What is the end of here string?
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
It seemed to me that the end of a here string is newline. I realize I am wrong:
$ cat <<< hello world
cat: world: No such file or directory
What can signify the end of a here string?
bash io-redirection here-string
add a comment |
up vote
0
down vote
favorite
It seemed to me that the end of a here string is newline. I realize I am wrong:
$ cat <<< hello world
cat: world: No such file or directory
What can signify the end of a here string?
bash io-redirection here-string
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
It seemed to me that the end of a here string is newline. I realize I am wrong:
$ cat <<< hello world
cat: world: No such file or directory
What can signify the end of a here string?
bash io-redirection here-string
It seemed to me that the end of a here string is newline. I realize I am wrong:
$ cat <<< hello world
cat: world: No such file or directory
What can signify the end of a here string?
bash io-redirection here-string
bash io-redirection here-string
asked Nov 22 at 21:28
Ben
2769
2769
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
3
down vote
accepted
The syntax of a here string is:
<<< word
where a word is a sequence of characters treated as a unit by the shell, delimited by whitespace. That could be a single regular word (hello
), a single- or double-quoted string ('hello world'
, "hello world"
), a parameter or command substitution ($foo
, $(...)
), something assembled with backslash escapes, or a combination of those joined together.
You can have multiple here-documents or here-strings on a single line, so the end of the line can't work as the only delimiter, though it will end there if not already (unless the newline is backslash-escaped).
You would get the effect you wanted with
cat <<<'hello world'
or
cat <<<hello world
@ilkkachu Yeah, you're right, there's no word-splitting there at all.
– Michael Homer
Nov 22 at 21:59
<<<
comes fromzsh
(and the Unix variant ofrc
), and$IFS
was never involved there (nor inksh93
normksh
noryash
which also copied that operator) but inbash
versions prior to 4.4, unquoted expansions in the word after<<<
were subject to word splitting (and the resulting words joined with space) which is why you do need to write it ascat <<< "$var"
if you want to support bash versions 4.3 or older. That was fixed in 4.4
– Stéphane Chazelas
Nov 22 at 22:46
add a comment |
up vote
2
down vote
From the manual:
[n]<<<word
The end is one word, not multiple words. So in this example, the first word is hello
and terminates the here string. The next word is world
, it is just an ordinary argument to cat
, and cat
assumes it is a file name to read.
You could write it more clearly this way:
$ cat world <<< hello
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
The syntax of a here string is:
<<< word
where a word is a sequence of characters treated as a unit by the shell, delimited by whitespace. That could be a single regular word (hello
), a single- or double-quoted string ('hello world'
, "hello world"
), a parameter or command substitution ($foo
, $(...)
), something assembled with backslash escapes, or a combination of those joined together.
You can have multiple here-documents or here-strings on a single line, so the end of the line can't work as the only delimiter, though it will end there if not already (unless the newline is backslash-escaped).
You would get the effect you wanted with
cat <<<'hello world'
or
cat <<<hello world
@ilkkachu Yeah, you're right, there's no word-splitting there at all.
– Michael Homer
Nov 22 at 21:59
<<<
comes fromzsh
(and the Unix variant ofrc
), and$IFS
was never involved there (nor inksh93
normksh
noryash
which also copied that operator) but inbash
versions prior to 4.4, unquoted expansions in the word after<<<
were subject to word splitting (and the resulting words joined with space) which is why you do need to write it ascat <<< "$var"
if you want to support bash versions 4.3 or older. That was fixed in 4.4
– Stéphane Chazelas
Nov 22 at 22:46
add a comment |
up vote
3
down vote
accepted
The syntax of a here string is:
<<< word
where a word is a sequence of characters treated as a unit by the shell, delimited by whitespace. That could be a single regular word (hello
), a single- or double-quoted string ('hello world'
, "hello world"
), a parameter or command substitution ($foo
, $(...)
), something assembled with backslash escapes, or a combination of those joined together.
You can have multiple here-documents or here-strings on a single line, so the end of the line can't work as the only delimiter, though it will end there if not already (unless the newline is backslash-escaped).
You would get the effect you wanted with
cat <<<'hello world'
or
cat <<<hello world
@ilkkachu Yeah, you're right, there's no word-splitting there at all.
– Michael Homer
Nov 22 at 21:59
<<<
comes fromzsh
(and the Unix variant ofrc
), and$IFS
was never involved there (nor inksh93
normksh
noryash
which also copied that operator) but inbash
versions prior to 4.4, unquoted expansions in the word after<<<
were subject to word splitting (and the resulting words joined with space) which is why you do need to write it ascat <<< "$var"
if you want to support bash versions 4.3 or older. That was fixed in 4.4
– Stéphane Chazelas
Nov 22 at 22:46
add a comment |
up vote
3
down vote
accepted
up vote
3
down vote
accepted
The syntax of a here string is:
<<< word
where a word is a sequence of characters treated as a unit by the shell, delimited by whitespace. That could be a single regular word (hello
), a single- or double-quoted string ('hello world'
, "hello world"
), a parameter or command substitution ($foo
, $(...)
), something assembled with backslash escapes, or a combination of those joined together.
You can have multiple here-documents or here-strings on a single line, so the end of the line can't work as the only delimiter, though it will end there if not already (unless the newline is backslash-escaped).
You would get the effect you wanted with
cat <<<'hello world'
or
cat <<<hello world
The syntax of a here string is:
<<< word
where a word is a sequence of characters treated as a unit by the shell, delimited by whitespace. That could be a single regular word (hello
), a single- or double-quoted string ('hello world'
, "hello world"
), a parameter or command substitution ($foo
, $(...)
), something assembled with backslash escapes, or a combination of those joined together.
You can have multiple here-documents or here-strings on a single line, so the end of the line can't work as the only delimiter, though it will end there if not already (unless the newline is backslash-escaped).
You would get the effect you wanted with
cat <<<'hello world'
or
cat <<<hello world
edited Nov 22 at 21:58
answered Nov 22 at 21:36
Michael Homer
44.8k7117156
44.8k7117156
@ilkkachu Yeah, you're right, there's no word-splitting there at all.
– Michael Homer
Nov 22 at 21:59
<<<
comes fromzsh
(and the Unix variant ofrc
), and$IFS
was never involved there (nor inksh93
normksh
noryash
which also copied that operator) but inbash
versions prior to 4.4, unquoted expansions in the word after<<<
were subject to word splitting (and the resulting words joined with space) which is why you do need to write it ascat <<< "$var"
if you want to support bash versions 4.3 or older. That was fixed in 4.4
– Stéphane Chazelas
Nov 22 at 22:46
add a comment |
@ilkkachu Yeah, you're right, there's no word-splitting there at all.
– Michael Homer
Nov 22 at 21:59
<<<
comes fromzsh
(and the Unix variant ofrc
), and$IFS
was never involved there (nor inksh93
normksh
noryash
which also copied that operator) but inbash
versions prior to 4.4, unquoted expansions in the word after<<<
were subject to word splitting (and the resulting words joined with space) which is why you do need to write it ascat <<< "$var"
if you want to support bash versions 4.3 or older. That was fixed in 4.4
– Stéphane Chazelas
Nov 22 at 22:46
@ilkkachu Yeah, you're right, there's no word-splitting there at all.
– Michael Homer
Nov 22 at 21:59
@ilkkachu Yeah, you're right, there's no word-splitting there at all.
– Michael Homer
Nov 22 at 21:59
<<<
comes from zsh
(and the Unix variant of rc
), and $IFS
was never involved there (nor in ksh93
nor mksh
nor yash
which also copied that operator) but in bash
versions prior to 4.4, unquoted expansions in the word after <<<
were subject to word splitting (and the resulting words joined with space) which is why you do need to write it as cat <<< "$var"
if you want to support bash versions 4.3 or older. That was fixed in 4.4– Stéphane Chazelas
Nov 22 at 22:46
<<<
comes from zsh
(and the Unix variant of rc
), and $IFS
was never involved there (nor in ksh93
nor mksh
nor yash
which also copied that operator) but in bash
versions prior to 4.4, unquoted expansions in the word after <<<
were subject to word splitting (and the resulting words joined with space) which is why you do need to write it as cat <<< "$var"
if you want to support bash versions 4.3 or older. That was fixed in 4.4– Stéphane Chazelas
Nov 22 at 22:46
add a comment |
up vote
2
down vote
From the manual:
[n]<<<word
The end is one word, not multiple words. So in this example, the first word is hello
and terminates the here string. The next word is world
, it is just an ordinary argument to cat
, and cat
assumes it is a file name to read.
You could write it more clearly this way:
$ cat world <<< hello
add a comment |
up vote
2
down vote
From the manual:
[n]<<<word
The end is one word, not multiple words. So in this example, the first word is hello
and terminates the here string. The next word is world
, it is just an ordinary argument to cat
, and cat
assumes it is a file name to read.
You could write it more clearly this way:
$ cat world <<< hello
add a comment |
up vote
2
down vote
up vote
2
down vote
From the manual:
[n]<<<word
The end is one word, not multiple words. So in this example, the first word is hello
and terminates the here string. The next word is world
, it is just an ordinary argument to cat
, and cat
assumes it is a file name to read.
You could write it more clearly this way:
$ cat world <<< hello
From the manual:
[n]<<<word
The end is one word, not multiple words. So in this example, the first word is hello
and terminates the here string. The next word is world
, it is just an ordinary argument to cat
, and cat
assumes it is a file name to read.
You could write it more clearly this way:
$ cat world <<< hello
answered Nov 22 at 21:34
RalfFriedl
5,0873925
5,0873925
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f483545%2fwhat-is-the-end-of-here-string%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