0
필자는 스크립트를 디버그하려고하는데, 배쉬에서 새로 왔고 오류를 줄이지 못했습니다. 줄을 60 개 표시 한 후 여러 번 변경하려고 시도했습니다. 오류 : 오류 : ./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] 가능한 가장 짧은 코드를 격리합니다. 같은 문제가이 질문을 상당히 잘 할 것입니다. –