Timeline for Is there a way to use HEREDOC for Bash and Zsh, and be able to use arguments?
Current License: CC BY-SA 4.0
11 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Dec 17, 2020 at 20:11 | comment | added | Stéphane Chazelas | @nonopolarity, I can't reproduce here on Ubuntu. I can read stdin OK with either approach. | |
| Dec 17, 2020 at 18:58 | comment | added | nonopolarity |
I then tried the ruby /dev/fd/3 "$@" 3<< 'EOF' method and it wasn't able to get the STDIN input either... I think if it can work perfectly, then we can achieve the goal of: we can run inline Ruby code exactly the same way, without needing to create a separate Ruby file
|
|
| Dec 17, 2020 at 18:49 | comment | added | nonopolarity |
I gave it a try using the ruby -e "$(cat << 'EOF' method and adding line = gets; puts "Ruby is getting the STDIN #{line}" to the Ruby script... and it wasn't able to get the STDIN input... if as a standalone Ruby script, then it can. I also tried ARGF.each do |line| and it was the same
|
|
| Dec 17, 2020 at 18:33 | comment | added | Stéphane Chazelas | See also Portability of file descriptor links | |
| Dec 17, 2020 at 18:25 | comment | added | Stéphane Chazelas |
Most modern systems support /dev/fd. Linux has had for decades. That feature is from the 80s. The only system I've personally come across that didn't have it was FreeBSD where it's available, but not enabled by default (or at least wasn't the last time I checked).
|
|
| Dec 17, 2020 at 18:17 | comment | added | Stéphane Chazelas |
<<< foo,from zsh is a herestring. That's different from Bourne's here doc in that here foo just makes up the contents of the heredoc.
|
|
| Dec 17, 2020 at 18:12 | comment | added | Stéphane Chazelas |
@nonopolarity, to test if it has it, try: cat /dev/fd/3 3<<< OK instead. The ruby -e "$(cat << 'EOF' approach would definitely be the more portable.
|
|
| Dec 17, 2020 at 18:07 | comment | added | nonopolarity |
The /dev/fd/3 method worked on Mac Big Sur... but does that mean it may not work in some other systems (Mojave... Linux)? If that's the case, then the ruby -e "$(cat << 'EOF' method actually might be best because we can supply some arguments and at the same time let STDIN open for the Ruby script to use and more universally acceptable?
|
|
| Dec 17, 2020 at 8:30 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 |
added 436 characters in body
|
| Dec 17, 2020 at 8:20 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 |
added 436 characters in body
|
| Dec 17, 2020 at 8:13 | history | answered | Stéphane Chazelas | CC BY-SA 4.0 |