如何在 Bash Shell 脚本循环中填充数组

如何在 Bash Shell 脚本循环中填充数组

cmdline> ls -la /.myScript.sh

   set index=0
    set usrlist[index]="null" 


        while read line
        do

        #Total lines read
        z=`echo $line| wc -l`
        lines=`expr $lines + $z`    

        # 2) #total unique user
        linesED=`echo $line | sed 's/[0-9]//g'`
        linesEDA=`echo ${linesED:10}` 
        userr=`echo $linesEDA | awk '{print $1}'`  

        for i in z
        do
            usrlist[i]=$userr
        done
            index=`expr $index + $i`
            echo ${usrlist[index]}# prints out data correctly but with 
                                  #error expr:non-integer argument 
        done
 echo ${usrlist[index]}#here blank output only

我想在末尾打印出数组的所有成员,没有错误

答案1

您需要引入一个文件,done例如while

done < myfile.txt

相关内容