Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在bash中创建数组时出错_Bash - Fatal编程技术网

在bash中创建数组时出错

在bash中创建数组时出错,bash,Bash,我有两个带有特定密钥的文件(一个是MAT1)。 对于这个关键字,我喜欢读取它对应的ID,将其与文件名一起放入一个数组中。 我尝试了以下方法(我不太熟悉bash编程): #/bin/bash Num=0 arr=($(查找-名称'*.mat'|排序)) 对于“${arr[@]}”中的i 做 文件=$(基本名称“${i}”) 而read-r行 做 name=“$line” 如果s=''read-r-a数组bash对空格敏感,则下面的行不能有空格 out[$num] = "${array[index+

我有两个带有特定密钥的文件(一个是MAT1)。 对于这个关键字,我喜欢读取它对应的ID,将其与文件名一起放入一个数组中。 我尝试了以下方法(我不太熟悉bash编程):

#/bin/bash
Num=0
arr=($(查找-名称'*.mat'|排序))
对于“${arr[@]}”中的i
做
文件=$(基本名称“${i}”)
而read-r行
做
name=“$line”

如果s=''read-r-a数组
bash
对空格敏感,则下面的行不能有空格

out[$num] = "${array[index+1]} $file "
至于错误的原因,shell将该特定行视为第一个单词,它是一个命令
out[$num]
,即
out[1]
。等等,其余部分作为它的参数
=
“${array[index+1]}$file”
,这没有任何意义。删除空格并执行jsut

out[$num]="${array[index+1]} $file"

bash
对空格敏感,下面的行不能有空格

out[$num] = "${array[index+1]} $file "
至于错误的原因,shell将该特定行视为第一个单词,它是一个命令
out[$num]
,即
out[1]
。等等,其余部分作为它的参数
=
“${array[index+1]}$file”
,这没有任何意义。删除空格并执行jsut

out[$num]="${array[index+1]} $file"