我正在编写此脚本以计算输入文件中的一些变量。我不知道为什么它不计算数组中的元素(应为500),而只计算1。
#initializing variables
timeout=5
headerFile="lab06.output"
dataFile="fortune500.tsv"
dataURL="http://www.tech.mtu.edu/~toarney/sat3310/lab09/"
dataPath="/home/pjvaglic/Documents/labs/lab06/data/"
curlOptions="--silent --fail --connect-timeout $timeout"
#creating the array
declare -a myWebsitearray #=('cut -d '\t' -f3 "dataPath$dataFile"')
#obtaining the data file
wget $dataURL$dataFile -O $dataPath$dataFile
#getting rid of the crap from dos
sed -e "s/^m//" $dataPath$dataFile | readarray -t $myWebsitesarray
readarray -t myWebsitesarray < <(cut -d, -f3 $dataPath$dataFile)
myWebsitesarray=("${#myWebsitesarray[@]:1}")
#printf '%s\n' "${myWebsitesarray2[@]}"
websitesCount=${#myWebsitesarray[*]}
echo $websitesCount
您正在用此行中的元素数覆盖数组
myWebsitesarray=("${#myWebsitesarray[@]:1}")
删除井号
myWebsitesarray=("${myWebsitesarray[@]:1}")
另外,遵循@chepner的建议也是不错的选择。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句