如何将整个关键字传递给 for 循环变量 | linux |

how to pass whole keyword into for loop variable | linux |

我有一个场景,我想在 cat 文件时将整个关键字传递给 for 循环

文件包含以下数据:demo.txt

$ABC=RAM
$$PQR='RAJ'
SKY is blue
flower '/d/m'

我的代码:

for i in `cat demo.txt`
do 
    echo $i
done 

$i 没有将整行作为关键字:SKY is blueflower '/d/m'

我的输出:

my demo :  $ABC=RAM
my demo :  $$PQR='RAJ'
my demo :  SKY     
my demo :  is      
my demo :  blue    
my demo :  flower  
my demo :  '/d/m'

您想逐行读取文件,并在变量中获取每个完整(未触及)的行,对吗?然后试试这个:

while IFS= read -r line; do
    printf "Line read is >%s<\n" "$line"
done < demo.txt