试图读取文件中的每一行,输出总是'cat $ file'

时间:2016-06-01 10:44:02

标签: linux bash

我试图在终端中显示文件的每一行,但输出始终是:

  

cat $ file

这是我的代码:

#!/bin/bash
file="users.csv"
IFS=''
echo "bobama, Barack Obama" > $file
echo "gbush, George Bush" >> $file
for line in `cat $file`;
do
        echo $line;
done

1 个答案:

答案 0 :(得分:0)

我用'cat $file'替换$(cat $file)解决了这个问题。

您可以在此处找到更好的解释: Why can't you use cat to read a file line by line where each line has delimiters