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 short it will put the content of that datafile into the variable ans.
< means redirection, the stdin (input) of the process will be coming from a file
$() means opening a subshell, in which the command above will be executed (which is just taking the content of that file and sending it to stdout)
" " means keeping the result of that shell (stdout) in one string, avoid splitting
in short it will put the content of that datafile into the variable ans.
< means redirection, the stdin (input) of the process will be coming from a file
$() means opening a subshell, in which the command above will be executed (which is just taking the content of that file and sending it to stdout)
" " means keeping the result of that shell (stdout) in one string, avoid splitting
But its not really the standard output of the command or is it that the redirection operator must be used in a context where the input can be read and so the command substitution just obliges and reads it and then dumps the contents to its stdout?
What that book apparently fails to state, (and the official Bash manual's Command Substitution also does not make clear), is that "$(<filename)" is a Bash extension, to optimize the commonly used "$(cat filename)".
One can consult the Bash source code, and see that the command substitution function has a specific check for whether the command starts with a stdin redirect, which shortcuts the bulk of the what the function would otherwise do, and simply reads the file.
i.e. Yes, this is a special case, which differs to how command substitution otherwise works.
What that book apparently fails to state, (and the official Bash manual's Command Substitution also does not make clear), is that "$(<filename)" is a Bash extension, to optimize the commonly used "$(cat filename)".
The bash manual seems pretty clear to me:
"The command substitution $(cat file) can be replaced by the equivalent but faster $(< file)."
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.