사실 점점되지 않습니다, 조건이
...
if [ $i -ge ${tLen} ]; then
echo "Maximum limit reached, i=$i"
fi
i=$(($i+1))
...
이 표현하는 것은 while
루프 안에 있습니다. i
은 초기 값이 0 인 카운터 변수입니다. tLen
은 내가 가로 지르는 배열의 길이를 저장합니다. i
이 tLen
에 도달해도이 상태는 true
이되지 않습니다. 내가 어디로 잘못 가고 있니?
이 내 전체 코드입니다 :
사실read filename
words=(5 2)
i=0
sed 's/ /\n/g' "$filename" >"tmp.txt"
while read word
do
words[i]=$word
i=$(($i+1))
awk "/$word/ {count += 1} END{print count}" "tmp.txt" >>"tmp2.dat"
done <"tmp.txt"
i=0
tLen=${#words[@]}
echo "Length of words: ${tLen}"
declare -A wordMap
while read count
do
if [ $i -ge ${tLen} ]; then
echo "Maximum length reached, i=$i"
break
fi
wordMap["${words[$i]}"]=$count
i=$(($i+1))
done <"tmp2.dat"
rm "tmp.txt"
rm "tmp2.dat"
나는 주어진 텍스트에서 각 단어의 빈도를 계산하기 위해 노력하고는 ...
나머지 코드는 게시하십시오. 그것은 당신이 [subshell 문제가]있어 (http://mywiki.wooledge.org/BashPitfalls#grep_foo_bar_.7C_while_read_-r.3B_do_.28.28count.2B-.2B-.29.29.3B_done) – l0b0
나를 위해 작동합니다. 첫번째 줄에'#!/bin/bash -xv'를 달아서 변수에 무엇이 있는지 살펴보십시오. – choroba
임에 오류가 발생했습니다. '나쁜 배열 첨자'는 무엇을 의미합니까? – batman