tables in scripts

Hi ,

I have two tables with same length t1 and t2, I want to cretae a new third table where i put the difference between the elements of t2 and t1,

t3[0]= t1[0] - t2[0]
t3[1]= t1[1] - t2[1]

I am new to scripts, any help please? thanks

Any help please??

It's not allowed to bump up questions, read the rules.

use the below example

area[5]=`expr ${area[11]} + ${area[13]}`

Sorry for repeating my question.

I tried this:
for element in ${#tab1[*]}

$tab_T1[$element]=`expr ${tab2[$element]} - ${tab1[$element]}`

do echo "$element"
done

echo ${#tab_T1[*]}

but it gives me error;
line 56: syntax error near unexpected token `$tab_T1[$element]=`expr ${tab2[$element]} - ${tab1[$element]} line 56: `$tab_T1[$element]=`expr ${tab2[$element]} - ${tab1[$element]}`'

try this

for element in tab1
$tab_T1[element]=`expr ${tab2[element]} - ${tab1[element]}`

I tried this

for element in `seq 1 50`
do

$tab_T1[element] = ` expr ${tab2[element]} - ${tab1[element]} `
echo "$element"
done

but had the same error

./T1: line 57: [1]: command not found
1
./T1: line 57: [2]: command not found
2
./T1: line 57: [3]: command not found
3
./T1: line 57: [4]: command not found
4
./T1: line 57: [5]: command not found
5
...

check this code and may be this helps you solve the problem


tab1[1]=1
tab2[1]=3
tab1[2]=1
tab2[2]=5
TOTAL=2

for ((i=1; i<=TOTAL; i++))
do
tabR=`expr ${tab2} - ${tab1}`
done

echo ${tabR[1]}