[英]Bash script and piping
I have the following simple bash script: 我有以下简单的bash脚本:
for VAR
do
echo file found $VAR
done
what I want is for it to print all the files that contain the extension .png. 我想要的是打印包含扩展名.png的所有文件。 I would expect the following command line to work, but it does not. 我希望以下命令行能够正常工作,但事实并非如此。 Why? 为什么?
ls *.png | myscript.sh
or 要么
./myscript.sh < `ls *.png`
您需要xargs
:
ls *.png | xargs myscript.sh
To read standard input script should look like: 读取标准输入脚本应如下所示:
while read line; do
echo file found $line
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.