interactive programs can typically read input from stdin, e.g.,
$ echo echo hello | bash
hello
or
$ echo 1 2 + p | dc
3
however, nix-shell
does not seem to behave this way, e.g.
$ echo hello | nix-shell -p hello
$
whereas the expected output would have been Hello, world!
.
using the trick suggested in nix-shell(1)
:
--command cmd
In the environment of the derivation, run the shell command cmd. This command is executed in an
interactive shell. (Use --run to use a non-interactive shell instead.) However, a call to exit is
implicitly added to the command, so the shell will exit after running the command. To prevent
this, add return at the end; e.g. --command "echo Hello; return" will print Hello and then drop
you into the interactive shell. This can be useful for doing any additional initialisation.
leads to an error:
$ echo hello | nix-shell -p hello --command return
/tmp/nix-shell-15399-0/rc: line 1: return: can only `return' from a function or sourced script
$
my versions of the relevant programs are these:
$ nix --version
nix (Nix) 2.3.2
$ bash --version
GNU bash, version 4.4.23(1)-release (x86_64-pc-linux-gnu)
$
hence my question: how do i make nix-shell
read from stdin, like bash
or dc
?