@derobert You'd think he could come up with something a little more obscure than Terminator as an example. There are tens of thousands of films/movies.
@MichaelHomer you should know. Has there been a version of bash where this would work?
while read var; do something; done < $(command)
I'm having a friendly argument with a user on SO.es who claims that while inelegant, that did actually work for him on bash v <4. And I find that very hard to believe.
If the output of command is a filename, and that's the filename that one wishes to read from, then the redirection < $(command) could work, though I would write it < "$(command)". It doesn't look like that really applies to the situation described there, though.
What's more interesting, is that different shells give different errors.
$ checkshell 'while read var; do echo $var; done < $(seq 3)'
bash : bash: $(seq 3): ambiguous redirect
csh : Illegal variable name.
dash : dash: 1: cannot open 1
2
3: No such file
fish : fish: Missing end to balance this while loop
while read var; do echo $var; done < $(seq 3)
^
git-shell : fatal: unrecognized command 'while read var; do echo $var; done < $(seq 3)'
ksh : ksh: 1
2
3: cannot open [No such file or directory]
mksh : mksh: can't open 1
2
3: No such file or directory
Or, limiting to the shells that actually support command substitution and that while loop format:
bash : bash: $(seq 3): ambiguous redirect
dash : dash: 1: cannot open 1
2
3: No such file
mksh : mksh: can't open 1
2
3: No such file or directory
sh : sh: $(seq 3): No such file or directory
yash : yash: redirection: cannot open file `1
2
3': No such file or directory
zsh : zsh:1: no such file or directory: 1
I would expect bash to give an error more similar to the one dash gives if one runs bash in POSIX mode. When bash is not in POSIX mode, it rejects attempts to redirect with a filename produced by an expansion on which word splitting occurs and produces multiple words. IIRC "ambiguous redirect" is the error message it gives in that situation.
terdon@tpad foo $ while IFS= read -r line; do echo "$line" ; done < $(seq 1)
bash: $(seq 1): No such file or directory
terdon@tpad foo $ while IFS= read -r line; do echo "$line" ; done < $(seq 2)
bash: $(seq 2): ambiguous redirect
So in the first case, it tries to open a file called 1 and fails with "no such file". Why is the second one ambiguous though?
I'm guessing it's something to do with word splitting as you said, and the presence of the newline, but why ambiguous?
$ while read var; do echo $var; done < $(perl -e 'print "foo" x 100')
bash: $(perl -e 'print "foo" x 100'): File name too long
$ while read var; do echo $var; done < $(perl -le 'print "foo"')
bash: $(perl -le 'print "foo"'): No such file or directory
$ while read var; do echo $var; done < $(perl -le 'print "foo\nbar\n"')
bash: $(perl -le 'print "foo\nbar\n"'): ambiguous redirect
I think it's considered ambiguous because the user might mean that no word splitting should happen, or might mean that split words should be rejoined, or might mean that all but the first word are intended as arguments to the command. Writing "$(seq 2)" instead of $(seq 2) should avoid that error.
What's even curiouser is that, apparently, on the user's Linux system (he just tested) it gives him a filename too long error but prints out the contents of the file in reverse before giving the error. He says he used this script:
I've gotta run, but I might try to reproduce that behavior later. I wonder if some versions of some shells might put the whole output of tac in the error message about the filename being too long, or something.
Background:
With cross account role someaccountrole, I have access to aws account xyz.
Case 1
To create a stack in account xyz, we upload the Cloudformation file through console.
Amidst stack creation in Events tab, we see the very first event, as shown below:
Case 2
We create EC2 in...
I finally posted my xorg.conf question here unix.stackexchange.com/questions/533745/…. I have several attempted xorg.conf files, and xrandr output that could useful to post, but I'm not sure how they can be posted without creating a giant wall of text, or via links that will be forever persistent.
Any suggestions on how to get that content into the question, or if it's really needed?
@Jesse_b yes, good point. I just wrote that to test U&L answers and I don't have multiple versions installed. Should be feasible with - - version though