#!/bin/bash
while read line
do
echo $line
done < filename
cat filename|while read line
do
echo $line
done
逐个获取字串的方法:
wlist="abc def ghi kjl opq"
for w in $wlist
do
echo $w
done
本文介绍使用Bash脚本逐行读取文件内容的方法,并给出通过for循环遍历字符串中每个字符的具体实现。该文旨在帮助读者理解如何用简单的Bash命令来处理文本文件及字符串。
#!/bin/bash
while read line
do
echo $line
done < filename
cat filename|while read line
do
echo $line
done
逐个获取字串的方法:
wlist="abc def ghi kjl opq"
for w in $wlist
do
echo $w
done
2894

被折叠的 条评论
为什么被折叠?