在Perl中,以下代码将从命令行args或stdin中指定的文件中读取:
while (<>) {
print($_);
}
Run Code Online (Sandbox Code Playgroud)
这很方便.我只是想知道在bash中从file或stdin读取的最简单方法是什么.
我试图让bash处理来自stdin的数据,但是没有运气.我的意思是以下工作:
echo "hello world" | test=($(< /dev/stdin)); echo test=$test
test=
echo "hello world" | read test; echo test=$test
test=
echo "hello world" | test=`cat`; echo test=$test
test=
Run Code Online (Sandbox Code Playgroud)
我想要输出的地方test=hello world.我试过把""引号括起来"$test"也不起作用.