Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Added Two Arrays But With Errors Post 303024230 by Chiadi on Thursday 4th of October 2018 07:05:47 AM
Old 10-04-2018
Added Two Arrays But With Errors

Please could someone have a look at the code below and spot the cause of the error.
Thanks in advance.
CODE BELOW: (code tags now added) My apologies please, that was my first time here.Smilie

Code:
#! /bin/bash
# file: whileloop.sh

arr1=(2 4 6 8)
arr2=(3 6 9 12)
arr3=()

indextotal=(${#arr1[@]})
i=0
sum=0
while [[ ${#arr1[@]} -eq ${#arr2[@]} ]] && [[ $i -le $indextotal ]] # ${#arr[@]} depicts the size of an array
do
    sum=$(( "${arr1[i]}"+"${arr2[i]}" )) 
    #echo $sum
    arr3=("${arr3[@]}" "$sum")
    i=$(( i+1 ))
done
echo "${arr3[@]}"

OUTPUT BELOW
Code:
whileloop.sh: line 13: +  : syntax error: operand expected (error token is "+  ")
5 10 15 20

Thanks,
Chiadi




Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 10-04-2018 at 10:57 AM..
 

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Adapter Errors and Link Errors

$ errpt | more IDENTIFIER TIMESTAMP T C RESOURCE_NAME DESCRIPTION 3074FEB7 0802050205 T H fscsi1 ADAPTER ERROR B8113DD1 0802050205 T H fcs1 LINK ERROR B8113DD1 0802050205 T H fcs1 LINK ERROR 3074FEB7 0802050205 T H fscsi0 ADAPTER ERROR B8113DD1 ... (0 Replies)
Discussion started by: mcastill66
0 Replies

2. AIX

Adapter Errors and Link Errors

$ errpt | more IDENTIFIER TIMESTAMP T C RESOURCE_NAME DESCRIPTION 3074FEB7 0802050205 T H fscsi1 ADAPTER ERROR B8113DD1 0802050205 T H fcs1 LINK ERROR B8113DD1 0802050205 T H fcs1 LINK ERROR 3074FEB7 0802050205 T H fscsi0 ADAPTER ERROR B8113DD1 ... (2 Replies)
Discussion started by: mcastill66
2 Replies

3. Shell Programming and Scripting

New Person Added to the Forum

Hello, I'm brand new to this forum. I am working on my first Bash shell script. We were given an exercise to get ready for the real assignment. I could use some help. The exercise is to "set two variables (i. e., file1 & file2) on the command line to the paths of the text files. We are to... (1 Reply)
Discussion started by: wcarp05
1 Replies

4. UNIX for Dummies Questions & Answers

Major OS errors/Bash errors help!!!!

Hi all, dummy here.... I have major errors on entering the shell. On login I get: -bash: dircolors: command not found -bash: tr: command not found -bash: fgrep: command not found -bash: grep: command not found -bash: grep: command not found -bash: id: command not found -bash: [: =: unary... (12 Replies)
Discussion started by: wcmmlynn
12 Replies

5. Shell Programming and Scripting

Unique value added

Guys, I am trying to get unique numbers which i can use as a primary key in a table. I tried using the <seconds_since_epoch>.<hostname> combination but since more than one process can run on the same machine at the same time, this won't be unique either. Can anyone tell me another way to do... (2 Replies)
Discussion started by: garric
2 Replies

6. Web Development

PHP arrays in arrays

PHP question... I have an SQL query that's pulled back user IDs as a set of columns. Rather than IDs, I want to use their names. So I have an array of columns $col with values 1,7,3,12 etc and I've got an array $person with values "Fred", "Bert", "Tom" etc So what I want to do is display the... (3 Replies)
Discussion started by: JerryHone
3 Replies

7. Programming

question about int arrays and file pointer arrays

if i declare both but don't input any variables what values will the int array and file pointer array have on default, and if i want to reset any of the elements of both arrays to default, should i just set it to 0 or NULL or what? (1 Reply)
Discussion started by: omega666
1 Replies

8. Programming

Arrays of strings in GFORTRAN errors

Hello I am using gfortran and I intended to do thiis: Module variables character(len=:), dimension(:), allocatable, array end module variables Sub test use variables integer (max_len) max_len=len_trim("something here") if(.not.allocated(array))... (1 Reply)
Discussion started by: pepe
1 Replies

9. AIX

LPAR cannot added disk

Dear All, I created a new partition through "Integrated Virtualization Manager" but there have an error when I added a new disk to the partition. The disk already created without any issue, Below error is to add the disk to the partition An error occured while modifying the assignments... (5 Replies)
Discussion started by: lckdanny
5 Replies
All times are GMT -4. The time now is 12:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy