在bash脚本中逐行读取 [英] Read line by line in bash script

查看:76
本文介绍了在bash脚本中逐行读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想执行以下操作,逐行读取文件,并将每行的值用作参数

I want to do the following, read line by line of a file and use the value per line as params

FILE="cat test"
echo "$FILE" | \
while read CMD; do
echo $CMD
done

但是当我执行echo $ CMD时,它只返回cat:S

but when I do the echo $CMD, it just returns cat :S

推荐答案

您所拥有的是将文本"cat test"传递到循环中.

What you have is piping the text "cat test" into the loop.

您只想要:

cat test | \
while read CMD; do
    echo $CMD
done

这篇关于在bash脚本中逐行读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆