且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

发送字符串标准输入

更新时间:2023-11-05 10:03:10

您可以使用一个行定界符

 猫<<< 这是从标准输入来了

以上是相同的

 猫<< EOF
这是从标准输入来
EOF

,也可以从命令输出重定向,像

 差异≤(LS /箱)≤(LS在/ usr / bin中)

也可以读作

 而读线

   回声= $行=
完成< SOME_FILE

或只是

 回声东西|读取参数

Is there a way to effectively do this in bash:

/my/bash/script < echo 'This string will be sent to stdin.'

I'm aware that I could pipe the output from the echo such as this:

echo 'This string will be piped to stdin.' | /my/bash/script

You can use one-line heredoc

cat <<< "This is coming from the stdin"

the above is the same as

cat <<EOF
This is coming from the stdin
EOF

or you can redirect output from a command, like

diff <(ls /bin) <(ls /usr/bin)

or you can read as

while read line
do
   echo =$line=
done < some_file

or simply

echo something | read param