我想用空行分隔myfile.txt作为分隔符并将每个值存储在数组中。在shell脚本中使用空行空间拆分文件并存储在数组中
fruit=mango, lime, orange,grape
car=nissan,
ford,
toyota,
honda
country=russia, england, ireland,
usa,
mexico,australia
colors=green, orange, purple, white,
yellow
我写了下面的脚本
while IFS='\n' read -r line || [[ -n "$line" ]]; do
if [[ $line != "" ]]; then
arr+=("$line")
echo "File Content : $line"
fi
done < myfile.txt
我遇到的问题是国家,它这样写的
File Content : country=russia, england, ireland
File Content : usa,
File Content : mexico,australia
我想将被打印为
File Content : country=russia, england, ireland, usa,mexico,australia
你能帮我调整我的吗?脚本。
在此先感谢
既然你说“数组”,这应该被标记不只是“壳”,但是对于具有数组支持的特定壳(如bash)。基准POSIX sh不支持数组。 –