Rava wrote:Bogomips wrote:Think there has been a bit of a misunderstanding here. What I meant was that I got the instruction from the Internet, and which I'm now using in my script. Not sure if this is the exact url, but the statement is very much the same
Code: Select all
$ read test < <(echo hello world)
$ echo $test
hello world
It's answer #14 at
http://stackoverflow.com/questions/2746 ... stdin-pipe
Ohhhhh I see, now that's something new to me... I have to find other occurences of that very syntax to fully understand it... *le dramatic sigh*
for your interest if any, that syntax is called
process substitution and in simply words it works providing the result of command execution (input if >() or output if <()) as a file you can use in place of any common file, in particular in shell redirection
so, a command like
allows you to show the contents of the root directory (directory listing, ls), as the same way you display the content of any other common file such as cat ~/.bashrc
You may wonder how it works or exactly what file are you displaying with that command, the answer is you're display a temporary file, that's how it works:
so when invoking
cat <(ls) you are displaying the contents of temporary file
/proc/self/fd/11 It's exactly the same mechanism of named pipes but it's done authomatically by the shell
You may wonder if it is these two command are the same:
and the answer is almost the same, the result for both commands is the same, you show the listing of current directory, but the first one uses the same shell for the only process while the latter uses two subshells one for each command which is slighty but important difference.
Of course you can use it also combined with redirection:
Code: Select all
$ cat | tr ' ' '-'
var name with spaces
var-name-with-spaces
$ tr ' ' '-' < <(cat)
var name with spaces
var-name-with-spaces