在Nushell脚本中,如何访问标准输入?
我想实现类似这样的效果:
# This is bash
echo one two three | nu mynuscript.nu
# This is mynuscript.nu
print $stdin
describe $stdin
在nushell中没有像 $stdin这样的东西,怎么办?
我正在使用nushell 0.112.1。
解决方案
你需要使用 --stdin 标志将标准输入重定向到脚本。同时还需要定义一个main函数来访问标准输入
def main [] {
print # the first command automatically gets the stdin
$in | describe
}
请按如下方式运行
echo one two three | nu --stdin mynuscript.nu
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。