ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
in this case the subshell will do a redirection on its stdin and after that will exit, there is nothing [else] to do. The "result" is that the content of stdin will arrive to stdout without any modification (finally you will get the content of the file).
Code:
$(cat file)
in this case the subshell will fork/exec an additional command, a cat which will read the file and send the content to the stdout of the subshell. The result will be the same, just in this case an additional binary (cat) was involved too.
At the end they produce exactly the same result, just the former one is much more efficient.
Code:
$(<file cat)
Now the file will be redirected to stdin by the subshell, but the shell will execute an additional cat command which will process that input (and will do nothing, just pass it to stdout). Again, functionally identical, but inefficient as the second example. (the only difference is: the subshell will create the file descriptor - open the file and pass it to cat or cat will open the file)
is specific to bash and zsh:
in this (sub shell) context, if the command is missing then stdin is connected to stdout, behaving like cat
Other shells need a command there:
Code:
$(cat < /tmp/file)
zsh does it even in a the main context:
Code:
< /tmp/file
reads the file, where other shells need
Code:
cat < /tmp/file
Consequently zsh writes the file (from stdin) with
Code:
> /tmp/file
where other shells need
Code:
cat > /tmp/file
Just seeing your last post - do you have zsh?
Last edited by MadeInGermany; 04-27-2021 at 02:09 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.