0
私はスクリプトをデバッグしようとしていますが、私はbashで新しく、エラーを理解できません 何度か試してみました。エラー:./scriptdemo.txt:行60:results_array:悪い配列の添字不正配列の添え字エラー
#!/bin/bash
echo the script is running
#this part uses preCourses script to get preCourse demends for the input
course
results_array=''
reqursion_counter=-2
result_courses_counter=0
function FindPreCourses {
let reqursion_counter++
i=0
grep $1 courses.list>file1
while read line; do
res=$(echo $line|grep $1)
arr_line[$i]=$res
let i++
done<file1
rm file1
j=0
while (($j<${#arr_line[*]}))
do
read -a array_of_words<<<${arr_line[$j]}
length_of_line=${#array_of_words[*]}
if [[ 10#"$1" -eq 10#"${array_of_words[0]}" ]]; then
temp_line=${array_of_words[*]}
fi
let j++
done
read -a line_of_course<<<$temp_line
k=0
len=${#line_of_course[*]}
mistake_chk=1
if (($mistake_chk==1)); then
while ([[ ${line_of_course[$len-$k-1]} = +([0-9]) ]])&&
(((10#${line_of_course[$len-$k-1]} > 10)))
do
results_array[$result_courses_counter]=${line_of_course[$len-$k-1]}
let result_courses_counter++
let k++
done
if (($reqursion_counter < $result_courses_counter-1)); then
FindPreCourses ${results_array[$reqursion_counter]}
fi
fi
}
FindPreCourses $1
final=($(printf "%s\n" "${results_array[@]}" | sort -n))
printf '%s\n' "${final[@]}"|uniq
}
#this function searching for the sign students at the right semester
function looking_for_students {
grep $2 *.course>info2
local counter=0
while read line
do
grep $2 *.course | read -a line | echo ${line[0]}>fileName:ID
let counter++
done < info2
echo the number of the students counter was signing at $2 semester is
$counter
}
見てください:http://www.shellcheck.net/ – Cyrus
'results_array'は配列ではありません、それは文字列です:' results_array = '' ' – Barmar
[mcve]同じ問題がこの質問をかなりうまくいくでしょう。 –