I'm trying to compare the output of my fizzbuzz.js
program:
for (let i = 1; i <= 100; i++) {
let out = "";
if (i % 3 == 0) out += "Fizz";
if (i % 5 == 0) out += "Buzz";
if (i % 3 && i % 5) out = i;
console.log(out);
}
with the contents of a expected-output.txt
file which contains:
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
[...]
I can't get process substitution to work:
diff -u expected-output.txt <(node fizzbuzz.js)
seems to hang indefinitely. What could be causing this?
My environment is macOS Mojave, bash 3.2.57, node v12.5.0.
EDIT: this seems to be a macOS issue. Everything works fine on a Ubuntu 18.04 machine with newer bash 4.4.19
diff -u expected-output.txt <(cat expected-output.txt)
terminate correctly? – FedKad Jul 14 '19 at 18:44node fizzbuzz.js | diff -u expected-output.txt -
? – FedKad Jul 14 '19 at 18:50read var <(echo hello)
didn't work as command substitution, butread var < <(echo hello)
does, I thought that was the problem. And @ChefTony comments help some times. At least for those who are fair and have the courage! thanks – jottbe Jul 14 '19 at 19:04diff
shouldn't need to seek. And if it did, it would probably give a clear error about it anyway. – ilkkachu Jul 14 '19 at 19:22read
reads from stdin, butdiff
expects a filename. The<(...)
expands to a file name, so can be used as-is withdiff
. On the other hand,< <(...)
redirects to stdin from that "file" – ilkkachu Jul 14 '19 at 19:23cat
command and thenode
command here. Since I have no access to a system similar to the OP's, I cannot do my own tests. – FedKad Jul 14 '19 at 19:29cat <(node fizzbuzz.js)
hang too? also, what doesls -l <(true)
say (I don't know about MacOS, but on some systems, bash will use named pipes for process substitutions). – Jul 14 '19 at 21:49cat <(node fizzbuzz.js)
hangs too, it displays the output but doesn't exit until I^C
.ls -l <(true)
returnsprw-rw---- 0 user staff 0 Jul 15 06:29 /dev/fd/63
– Chef Tony Jul 15 '19 at 04:30