【发布时间】:2023-03-08 04:05:02
【问题描述】:
我对“IFS=$'\n' 有疑问。
old_IFS=$IFS
file="Good morning
Good morning
Good morning
Good morning
Good morning"
IFS=$'\n'
for line in $file
do
echo $line
done
IFS=$old_IFS
当我执行脚本时:
Good mor
i
g
Good mor
i
g
Good mor
i
g
Good mor
i
g
Good mor
i
g
“n”被删除。 我想逐行查看文件
【问题讨论】:
-
您使用的是哪个外壳?它是否支持
$'...'字符串语法? (反问句;显然不是。) -
如果您在脚本顶部使用
#!/bin/sh,请尝试更改为#!/bin/bash或#!/bin/ksh。祝你好运。 -
必须用shell写。我正在使用#!/bin/sh。谢谢。