4 ms·
Say I have a command that I want to read both a piped in stdin _and_ interactive input from the user. Is there a saner way to facilitate this than what I have
by frou_dh 11y ago
Say I have a command that I want to read both a piped in stdin _and_ interactive input from the user.
Is there a saner way to facilitate this than what I have done? Which is to run it like this from the shell:
something | mycmd 10<&1
and in mycmd read stdin as normal and interactive input from /dev/fd/10
- chousuke 11y agoI'm not sure if this is POSIX, but if you program accepts positional arguments, in bash you can do eg.: diff <(somecommand) <(someothercommand) and the shell will replace these with /dev/fd/<n>, allowing you to also accept standard input without relying on hardcoded file descriptors.
- frou_dh 11y agoCool tip. You're right though, bash in /bin/sh mode doesn't have that feature.
- teddyh 11y agoRead from stdin as normal, and read interactive input from /dev/tty.
- frou_dh 11y agoThat's the ticket!