I do have a interesting problem that I am trying to tackle but I amyet unable to do so.Let suppose that I have 2 arrays.Array One:1 -2 3 -2 2 -4Array Two:-2 -3 4 5 2 -5I want to be able to actually compare the i-th value of both Array one and Array two:If both are negative then I would input in Array Three 0If they are both positive I will add a 1If they are opposites I need to insert a 2Output:2 0 1 2 1 0 How can I do that ?
Comparing Negative values in bash using arrays
bash
If you're familiar with C, C++ or Java, then you'll find this variant of bash's for-loop quite familiar too.  bash does arithmetic evaluation with (( ... )) so we'll use that when comparing values:array1=(  1 -2  3 -2  2 -4 )array2=( -2 -3  4  5  2 -5 )array3=( )for (( i=0; i < ${#array1[@]}; ++i )); do    if (( array1[i] < 0 && array2[i] < 0 )); then        array3[$i]=0    elif (( array1[i] > 0 && array2[i] > 0 )); then        array3[$i]=1    else        array3[$i]=2    fidoneecho ${array3[@]}This also works well with the ksh93 shell, from which bash got many of its features.