我如何在bash脚本的while循环之外访问数组?

时间:2018-11-15 21:16:37

标签: linux bash shell scripting

echo "Enter the target file name : "
read target
space="                 "
echo -e "$space ${bold}Effect of double spacing ${normal} "
i=0
tac $target | while read line; do
    field[$i]=$line
    echo -e "\n${field[$i]}"
    i=expr $i+1
done
######
cat $target | while read line; do
    arr_length=${#field[@]}
        echo -n "Array length=$arr_length";
        i1=0;
        while (( $i1 < $arr_length ))
        do
            echo "${field[$i1]}" > $target
            echo -e "\n" > $target
            i1=expr $i1+1
        done
done

$array_length变量获得了0的值,因为在while循环之外无法访问数组。

有没有办法做到这一点???

0 个答案:

没有答案