LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   bash parallel cant generate correct array like my error shell demo (https://www.linuxquestions.org/questions/programming-9/bash-parallel-cant-generate-correct-array-like-my-error-shell-demo-4175488908/)

doomaway 12-22-2013 11:25 PM

bash parallel cant generate correct array like my error shell demo
 
hi all ,below is my script any suggetion

Quote:

#!/bin/bash
tmp_fifofile="/tmp/$.fifo"
mkfifo $tmp_fifofile
exec 6<>$tmp_fifofile
rm $tmp_fifofile
thread=1
for ((i=0;i<$thread;i++));do
echo
done >&6 #
#item1
for (( j=0;j<10;j++ ))
do
brr[$j]=`echo $RANDOM`
done
#item2
for (( i=0;i<10;i++ ))
do
read -u6
{
arr[$i]=`echo $RANDOM`
echo >&6
} &
done
wait
exec 6>&- # close f6

#print info

echo "array equal"${arr[1]}
echo "brray equal"${brr[1]}
echo "gerenate array Successful"
#end

item1 generate array general way

item2 generate brray by parallel way

so perform result is
[root@doom tbctemp]#sh 2.t
array equal
brray equal8516
gerenate array Successful



give me a helping hand
thanks in advances!

gnashley 01-13-2014 12:27 AM

Sorry, I refuse to read scripts without indentation.

grail 01-13-2014 02:10 AM

In the Op's defense, he has simply used the wrong bbcode.

OP - Please change the 'quote' tags to 'code' tags and your formatting will be preserved :)


All times are GMT -5. The time now is 06:03 PM.