【发布时间】:2020-07-03 14:53:15
【问题描述】:
交互式程序通常可以从标准输入读取输入,例如,
$ echo echo hello | bash
hello
或
$ echo 1 2 + p | dc
3
但是,nix-shell 似乎没有这种行为,例如
$ echo hello | nix-shell -p hello
$
而预期的输出应该是Hello, world!。
使用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.
导致错误:
$ 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
$
我的相关程序版本如下:
$ nix --version
nix (Nix) 2.3.2
$ bash --version
GNU bash, version 4.4.23(1)-release (x86_64-pc-linux-gnu)
$
因此我的问题是:我如何让nix-shell 从标准输入中读取,例如bash 或dc?
【问题讨论】: