Why are required to use /dev/tcpwriting a command transcript to fileWhy are bash_completion scripts persistently in environment?Bash is automatically reloading (injecting) updates into a running script upon saving it: Why? Any practical use?Zenity refuses to work in backgroundWhy are UNIX shells like this and how can I work around it?Is there a tool that automatically inserts and updates a script header block for e.g. shell or Python scripts?Why Can't I Call Two Aliases With “;”?Why is this code not working?sed stripping comments inlineWhy are true and false so large?
Constitutionality of U.S. Democratic Presidential Candidate's Supreme Court Suggestion
`-` in tar xzf -
What is the origin of Scooby-Doo's name?
Why tighten down in a criss-cross pattern?
Am I legally required to provide a (GPL licensed) source code even after a project is abandoned?
career in signal processing
Prime sieve in Python
Has there been any indication at all that further negotiation between the UK and EU is possible?
Can Ogre clerics use Purify Food and Drink on humanoid characters?
How does DC work with natural 20?
Did the CIA blow up a Siberian pipeline in 1982?
Designing a magic-compatible polearm
"Correct me if I'm wrong"
Why does the Saturn V have standalone inter-stage rings?
RandomInteger with equal number of 1 and -1
How would modern naval warfare have to have developed differently for battleships to still be relevant in the 21st century?
Android Material and appcompat Manifest merger failed in react-native or ExpoKit
Encounter design and XP thresholds
Why does independence imply zero correlation?
What are Elsa's reasons for selecting the Holy Grail on behalf of Donovan?
Where's this swanky house and vineyard near a mountain?
How do I professionally let my manager know I'll quit over an issue?
Is "Busen" just the area between the breasts?
Story about hunting giant lizards for hides on privately owned planet
Why are required to use /dev/tcp
writing a command transcript to fileWhy are bash_completion scripts persistently in environment?Bash is automatically reloading (injecting) updates into a running script upon saving it: Why? Any practical use?Zenity refuses to work in backgroundWhy are UNIX shells like this and how can I work around it?Is there a tool that automatically inserts and updates a script header block for e.g. shell or Python scripts?Why Can't I Call Two Aliases With “;”?Why is this code not working?sed stripping comments inlineWhy are true and false so large?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
When trying to call /dev/tcp/www.google.com/80
, by typing
/dev/tcp/www.google.com/80
Bash says no such file or directory
. When looking at other people's code online, they use syntax such as
3<>/dev/tcp/www.google.com/80
I noticed that this works as well:
</dev/tcp/www.google.com/80
Why are these symbols required to call certain things in bash?
linux bash io-redirection devices
New contributor
add a comment |
When trying to call /dev/tcp/www.google.com/80
, by typing
/dev/tcp/www.google.com/80
Bash says no such file or directory
. When looking at other people's code online, they use syntax such as
3<>/dev/tcp/www.google.com/80
I noticed that this works as well:
</dev/tcp/www.google.com/80
Why are these symbols required to call certain things in bash?
linux bash io-redirection devices
New contributor
What do you mean by “call”? Please show us what you are doing, when you get the error. Are you trying to execute it? Even if the front page of google was executable code, I would not recommend it.
– ctrl-alt-delor
10 hours ago
/dev/tcp/www.google.com/80
– john doe
10 hours ago
I edited your question, to say what I thing you mean.
– ctrl-alt-delor
10 hours ago
add a comment |
When trying to call /dev/tcp/www.google.com/80
, by typing
/dev/tcp/www.google.com/80
Bash says no such file or directory
. When looking at other people's code online, they use syntax such as
3<>/dev/tcp/www.google.com/80
I noticed that this works as well:
</dev/tcp/www.google.com/80
Why are these symbols required to call certain things in bash?
linux bash io-redirection devices
New contributor
When trying to call /dev/tcp/www.google.com/80
, by typing
/dev/tcp/www.google.com/80
Bash says no such file or directory
. When looking at other people's code online, they use syntax such as
3<>/dev/tcp/www.google.com/80
I noticed that this works as well:
</dev/tcp/www.google.com/80
Why are these symbols required to call certain things in bash?
linux bash io-redirection devices
linux bash io-redirection devices
New contributor
New contributor
edited 1 hour ago
mosvy
14k21547
14k21547
New contributor
asked 11 hours ago
john doejohn doe
234
234
New contributor
New contributor
What do you mean by “call”? Please show us what you are doing, when you get the error. Are you trying to execute it? Even if the front page of google was executable code, I would not recommend it.
– ctrl-alt-delor
10 hours ago
/dev/tcp/www.google.com/80
– john doe
10 hours ago
I edited your question, to say what I thing you mean.
– ctrl-alt-delor
10 hours ago
add a comment |
What do you mean by “call”? Please show us what you are doing, when you get the error. Are you trying to execute it? Even if the front page of google was executable code, I would not recommend it.
– ctrl-alt-delor
10 hours ago
/dev/tcp/www.google.com/80
– john doe
10 hours ago
I edited your question, to say what I thing you mean.
– ctrl-alt-delor
10 hours ago
What do you mean by “call”? Please show us what you are doing, when you get the error. Are you trying to execute it? Even if the front page of google was executable code, I would not recommend it.
– ctrl-alt-delor
10 hours ago
What do you mean by “call”? Please show us what you are doing, when you get the error. Are you trying to execute it? Even if the front page of google was executable code, I would not recommend it.
– ctrl-alt-delor
10 hours ago
/dev/tcp/www.google.com/80
– john doe
10 hours ago
/dev/tcp/www.google.com/80
– john doe
10 hours ago
I edited your question, to say what I thing you mean.
– ctrl-alt-delor
10 hours ago
I edited your question, to say what I thing you mean.
– ctrl-alt-delor
10 hours ago
add a comment |
2 Answers
2
active
oldest
votes
Because that's a feature of the shell (of ksh, copied by bash), and the shell only.
/dev/tcp/...
are not real files, the shell intercepts the attempts to redirect to a /dev/tcp/...
file and then does a socket(...);connect(...)
(makes a TCP connection) instead of a open("/dev/tcp/..."...)
(opening that file) in that case.
Note that it has to be spelled like that. cat < /dev/./tcp/...
or ///dev/tcp/...
won't work, and will attempt to open those files instead (which on most systems don't exist and you'll get an error).
When you do cat /dev/tcp/...
, that doesn't work because cat
doesn't implement that same special handling, it does a open("/dev/tcp/...")
like for every file (except -
), only the shell (ksh, bash only) does, and only for the target of redirections.
That cat -
is another example of a file path handled specially. Instead of doing a open("-")
, it reads directly from the file descriptor 0 (stdin). cat
and many text utilities do that, the shell doesn't for its redirections. To read the content of the -
file, you need cat ./-
, or cat < -
(or cat - < -
). On systems that don't a have /dev/stdin
, bash
will however do something similar for redirections from that (virtual) file. GNU awk
does the same for /dev/stdin
, /dev/stdout
, /dev/stderr
even on systems that do have such files which can cause some surprises on systems like Linux where those files behave differently.
zsh
also has TCP (and Unix domain stream) socket support, but that's done with a ztcp
(and zsocket
) builtins, so it's less limited than the ksh/bash approach. In particular, it can also act as a server which ksh/bash can't do. It's still much more limited than what you can do in a real programming language though.
add a comment |
You seem to be confusing the ideas or reading a file and executing a command. The difference between data and instruction.
Googles front page is not an executable program. And if it was, it would not be safe to run it.
The redirection characters (including <
and >
), are used to direct data into a command.
We could do cat < /dev/tcp/towel.blinkenlights.nl/23
However this won't work for /dev/tcp/www.google.com/80
as this port will not respond until we send GET / HTTP/1.1nn
So try
exec 3<>/dev/tcp/www.google.com/80
echo -e >&3 "GET / HTTP/1.1nn"
cat <&3 #this does not return (in good time), as the connection is not closed.
exec 3>&-
add a comment |
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',
autoActivateHeartbeat: false,
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
);
);
john doe is a new contributor. Be nice, and check out our Code of Conduct.
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%2f525653%2fwhy-are-or-required-to-use-dev-tcp%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Because that's a feature of the shell (of ksh, copied by bash), and the shell only.
/dev/tcp/...
are not real files, the shell intercepts the attempts to redirect to a /dev/tcp/...
file and then does a socket(...);connect(...)
(makes a TCP connection) instead of a open("/dev/tcp/..."...)
(opening that file) in that case.
Note that it has to be spelled like that. cat < /dev/./tcp/...
or ///dev/tcp/...
won't work, and will attempt to open those files instead (which on most systems don't exist and you'll get an error).
When you do cat /dev/tcp/...
, that doesn't work because cat
doesn't implement that same special handling, it does a open("/dev/tcp/...")
like for every file (except -
), only the shell (ksh, bash only) does, and only for the target of redirections.
That cat -
is another example of a file path handled specially. Instead of doing a open("-")
, it reads directly from the file descriptor 0 (stdin). cat
and many text utilities do that, the shell doesn't for its redirections. To read the content of the -
file, you need cat ./-
, or cat < -
(or cat - < -
). On systems that don't a have /dev/stdin
, bash
will however do something similar for redirections from that (virtual) file. GNU awk
does the same for /dev/stdin
, /dev/stdout
, /dev/stderr
even on systems that do have such files which can cause some surprises on systems like Linux where those files behave differently.
zsh
also has TCP (and Unix domain stream) socket support, but that's done with a ztcp
(and zsocket
) builtins, so it's less limited than the ksh/bash approach. In particular, it can also act as a server which ksh/bash can't do. It's still much more limited than what you can do in a real programming language though.
add a comment |
Because that's a feature of the shell (of ksh, copied by bash), and the shell only.
/dev/tcp/...
are not real files, the shell intercepts the attempts to redirect to a /dev/tcp/...
file and then does a socket(...);connect(...)
(makes a TCP connection) instead of a open("/dev/tcp/..."...)
(opening that file) in that case.
Note that it has to be spelled like that. cat < /dev/./tcp/...
or ///dev/tcp/...
won't work, and will attempt to open those files instead (which on most systems don't exist and you'll get an error).
When you do cat /dev/tcp/...
, that doesn't work because cat
doesn't implement that same special handling, it does a open("/dev/tcp/...")
like for every file (except -
), only the shell (ksh, bash only) does, and only for the target of redirections.
That cat -
is another example of a file path handled specially. Instead of doing a open("-")
, it reads directly from the file descriptor 0 (stdin). cat
and many text utilities do that, the shell doesn't for its redirections. To read the content of the -
file, you need cat ./-
, or cat < -
(or cat - < -
). On systems that don't a have /dev/stdin
, bash
will however do something similar for redirections from that (virtual) file. GNU awk
does the same for /dev/stdin
, /dev/stdout
, /dev/stderr
even on systems that do have such files which can cause some surprises on systems like Linux where those files behave differently.
zsh
also has TCP (and Unix domain stream) socket support, but that's done with a ztcp
(and zsocket
) builtins, so it's less limited than the ksh/bash approach. In particular, it can also act as a server which ksh/bash can't do. It's still much more limited than what you can do in a real programming language though.
add a comment |
Because that's a feature of the shell (of ksh, copied by bash), and the shell only.
/dev/tcp/...
are not real files, the shell intercepts the attempts to redirect to a /dev/tcp/...
file and then does a socket(...);connect(...)
(makes a TCP connection) instead of a open("/dev/tcp/..."...)
(opening that file) in that case.
Note that it has to be spelled like that. cat < /dev/./tcp/...
or ///dev/tcp/...
won't work, and will attempt to open those files instead (which on most systems don't exist and you'll get an error).
When you do cat /dev/tcp/...
, that doesn't work because cat
doesn't implement that same special handling, it does a open("/dev/tcp/...")
like for every file (except -
), only the shell (ksh, bash only) does, and only for the target of redirections.
That cat -
is another example of a file path handled specially. Instead of doing a open("-")
, it reads directly from the file descriptor 0 (stdin). cat
and many text utilities do that, the shell doesn't for its redirections. To read the content of the -
file, you need cat ./-
, or cat < -
(or cat - < -
). On systems that don't a have /dev/stdin
, bash
will however do something similar for redirections from that (virtual) file. GNU awk
does the same for /dev/stdin
, /dev/stdout
, /dev/stderr
even on systems that do have such files which can cause some surprises on systems like Linux where those files behave differently.
zsh
also has TCP (and Unix domain stream) socket support, but that's done with a ztcp
(and zsocket
) builtins, so it's less limited than the ksh/bash approach. In particular, it can also act as a server which ksh/bash can't do. It's still much more limited than what you can do in a real programming language though.
Because that's a feature of the shell (of ksh, copied by bash), and the shell only.
/dev/tcp/...
are not real files, the shell intercepts the attempts to redirect to a /dev/tcp/...
file and then does a socket(...);connect(...)
(makes a TCP connection) instead of a open("/dev/tcp/..."...)
(opening that file) in that case.
Note that it has to be spelled like that. cat < /dev/./tcp/...
or ///dev/tcp/...
won't work, and will attempt to open those files instead (which on most systems don't exist and you'll get an error).
When you do cat /dev/tcp/...
, that doesn't work because cat
doesn't implement that same special handling, it does a open("/dev/tcp/...")
like for every file (except -
), only the shell (ksh, bash only) does, and only for the target of redirections.
That cat -
is another example of a file path handled specially. Instead of doing a open("-")
, it reads directly from the file descriptor 0 (stdin). cat
and many text utilities do that, the shell doesn't for its redirections. To read the content of the -
file, you need cat ./-
, or cat < -
(or cat - < -
). On systems that don't a have /dev/stdin
, bash
will however do something similar for redirections from that (virtual) file. GNU awk
does the same for /dev/stdin
, /dev/stdout
, /dev/stderr
even on systems that do have such files which can cause some surprises on systems like Linux where those files behave differently.
zsh
also has TCP (and Unix domain stream) socket support, but that's done with a ztcp
(and zsocket
) builtins, so it's less limited than the ksh/bash approach. In particular, it can also act as a server which ksh/bash can't do. It's still much more limited than what you can do in a real programming language though.
edited 10 hours ago
answered 10 hours ago
Stéphane ChazelasStéphane Chazelas
322k57620986
322k57620986
add a comment |
add a comment |
You seem to be confusing the ideas or reading a file and executing a command. The difference between data and instruction.
Googles front page is not an executable program. And if it was, it would not be safe to run it.
The redirection characters (including <
and >
), are used to direct data into a command.
We could do cat < /dev/tcp/towel.blinkenlights.nl/23
However this won't work for /dev/tcp/www.google.com/80
as this port will not respond until we send GET / HTTP/1.1nn
So try
exec 3<>/dev/tcp/www.google.com/80
echo -e >&3 "GET / HTTP/1.1nn"
cat <&3 #this does not return (in good time), as the connection is not closed.
exec 3>&-
add a comment |
You seem to be confusing the ideas or reading a file and executing a command. The difference between data and instruction.
Googles front page is not an executable program. And if it was, it would not be safe to run it.
The redirection characters (including <
and >
), are used to direct data into a command.
We could do cat < /dev/tcp/towel.blinkenlights.nl/23
However this won't work for /dev/tcp/www.google.com/80
as this port will not respond until we send GET / HTTP/1.1nn
So try
exec 3<>/dev/tcp/www.google.com/80
echo -e >&3 "GET / HTTP/1.1nn"
cat <&3 #this does not return (in good time), as the connection is not closed.
exec 3>&-
add a comment |
You seem to be confusing the ideas or reading a file and executing a command. The difference between data and instruction.
Googles front page is not an executable program. And if it was, it would not be safe to run it.
The redirection characters (including <
and >
), are used to direct data into a command.
We could do cat < /dev/tcp/towel.blinkenlights.nl/23
However this won't work for /dev/tcp/www.google.com/80
as this port will not respond until we send GET / HTTP/1.1nn
So try
exec 3<>/dev/tcp/www.google.com/80
echo -e >&3 "GET / HTTP/1.1nn"
cat <&3 #this does not return (in good time), as the connection is not closed.
exec 3>&-
You seem to be confusing the ideas or reading a file and executing a command. The difference between data and instruction.
Googles front page is not an executable program. And if it was, it would not be safe to run it.
The redirection characters (including <
and >
), are used to direct data into a command.
We could do cat < /dev/tcp/towel.blinkenlights.nl/23
However this won't work for /dev/tcp/www.google.com/80
as this port will not respond until we send GET / HTTP/1.1nn
So try
exec 3<>/dev/tcp/www.google.com/80
echo -e >&3 "GET / HTTP/1.1nn"
cat <&3 #this does not return (in good time), as the connection is not closed.
exec 3>&-
answered 9 hours ago
ctrl-alt-delorctrl-alt-delor
13.4k52964
13.4k52964
add a comment |
add a comment |
john doe is a new contributor. Be nice, and check out our Code of Conduct.
john doe is a new contributor. Be nice, and check out our Code of Conduct.
john doe is a new contributor. Be nice, and check out our Code of Conduct.
john doe is a new contributor. Be nice, and check out our Code of Conduct.
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.
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%2f525653%2fwhy-are-or-required-to-use-dev-tcp%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
What do you mean by “call”? Please show us what you are doing, when you get the error. Are you trying to execute it? Even if the front page of google was executable code, I would not recommend it.
– ctrl-alt-delor
10 hours ago
/dev/tcp/www.google.com/80
– john doe
10 hours ago
I edited your question, to say what I thing you mean.
– ctrl-alt-delor
10 hours ago