使用bash脚本读取文件 [英] Read a file using a bash script
本文介绍了使用bash脚本读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用执行/同时执行"循环读取文件.
如何以字符串形式读取内容?
I need to read a file using a "Do/While" loop.
How can I read the contents as a string?
这是我的代码:
cat directory/scripts/tv2dbarray.txt | while read line
do
echo "a line: $line"
done
错误:
test.sh: line 4: syntax error near unexpected token `done'
test.sh: line 4: `done'
推荐答案
cat file | while read line
do
echo "a line: $line"
done
要将文件内容放入var中,请使用:
To get file contents into a var use:
foo="`cat file`"
这篇关于使用bash脚本读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文