我正在尝试将数组的内容放入一个文件中,并将数组的每个元素放在文件的新行中。
IFS=$'\n'
echo "${mtches[@]}" > sample1.txt
Run Code Online (Sandbox Code Playgroud)
mtches 的内容是“qwe”和“asd”。但该sample1.txt文件包含qwe asd在一行中。为什么不考虑 IFS 值?
这是我的 grep 搜索
grep 'Invoker_Slark*' true_pairscore.txt
Run Code Online (Sandbox Code Playgroud)
但它返回 line Invoker_Slardar。即使该文件包含Invoker_Slark. 这是为什么?
我正在尝试构造一个数组并以这种格式写入文件,即文件的内容应该是这样的
hero_pairscore=( askdjfh sdf,sdlkfj lksf,dfgdf,dsflkgj,asdlkf ....)
Run Code Online (Sandbox Code Playgroud)
其中元素由comma. 我为此编写了以下代码。
#!/bin/bash
#set -x
hero_pairscore=()
while read line
do
$( IFS=",";hero_pairscore+=( "$line" )
done < true_pairscore.txt
echo "hero_pairscore=( ${hero_pairscore[@]} )" > embed.txt
Run Code Online (Sandbox Code Playgroud)
但是生成的文件只包含这个hero_pairscore=( ). 我的代码有什么问题,如何更正它以提供所需的输出?