我有一个脚本,我正逐行将文件读入数组。
#!/bin/bash
echo "Enter audio file name. (File must be of .wav format)"
read fileName
echo "Enter path of the audio file"
read path
echo "Enter folder name"
read outputfolder
mkdir -p $outputfolder
echo "Processing $fileName"
./ilp_diarization2.sh $path/$fileName.wav 120 $outputfolder
#value="$(grep "$fileName.*S" $outputfolder/$fileName/$fileName.g.3.seg)"
#echo "${value}"
awk '{ print $3" "$4}' $outputfolder/$fileName/$fileName.g.3.seg > a
#var=$(awk '{ print $1 }' a) > 2
#echo "${var[0]}
getArray() {
array=() # Create array
while IFS= read -r line # Read a line
do
array+=("$line") # Append line to the array
done < "$1"
}
getArray "a" #file name
我遇到的错误是数组减速。
Syntax error: "(" unexpected (expecting "}")
我尝试过使用
array="()"
但它们似乎都不起作用。
以下是文件的内容:
S0 [
42 4677
S10 [
4719 1266
6020 3618
9667 8463
答案 0 :(得分:1)
似乎您的版本不支持数组,否则readarray
是内置的bash并且与函数相同
help readarray
readarray -t my_array < filename