Invalid arithmetic operator on string concatenation


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Invalid arithmetic operator on string concatenation
# 1  
Old 11-30-2016
Invalid arithmetic operator on string concatenation

Hello.

Code:
LEAP_VERSION="4.2"
export ARRAY_MAIN_REPO_LEAP=('zypper_local' 'openSUSE-Leap-'"$LEAP_VERSION"'-Non-Oss'  'openSUSE-Leap-'"$LEAP_VERSION"'-Oss'  'openSUSE-Leap-'"$LEAP_VERSION"'-Update'  'openSUSE-Leap-'"$LEAP_VERSION"'-Update-Non-Oss')

Seems that the - is interpreted as a numeric operation when next to $VAR

The error is :
Quote:
bash: 4.2: syntax error: invalid arithmetic operator (error token is ".2")
I was expecting this result :
Quote:
zypper_local openSUSE-Leap-4.2-Non-Oss openSUSE-Leap-4.2-Oss openSUSE-Leap-4.2-Update openSUSE-Leap-4.2-Update-Non-Oss
I am using bash : 4.3-79.15
Any help is welcome.
# 2  
Old 11-30-2016
What you have works fine with bash version 3.2.57 and with recent Korn shells.

You might consider trying:
Code:
export ARRAY_MAIN_REPO_LEAP=('zypper_local' "openSUSE-Leap-$LEAP_VERSION-Non-Oss"  "openSUSE-Leap-$LEAP_VERSION-Oss" "openSUSE-Leap-$LEAP_VERSION-Update"  "openSUSE-Leap-$LEAP_VERSION-Update-Non-Oss")

or:
Code:
export ARRAY_MAIN_REPO_LEAP=('zypper_local' openSUSE-Leap-"$LEAP_VERSION"-Non-Oss  openSUSE-Leap-"$LEAP_VERSION"-Oss  openSUSE-Leap-"$LEAP_VERSION"-Update  openSUSE-Leap-"$LEAP_VERSION"-Update-Non-Oss)

What does the output from:
Code:
printf '%s' "$IFS" | od -bc

look like when your array assignment fails?
# 3  
Old 05-14-2017
Yes that work.
Thank you for helping
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

BC calculation for floating (invalid arithmetic operator )

Hi, I wish to compare the CPU LOAD 1 min with 5mins and 15mins. If 1 min's CPU LOAd spike 3% compare to 5 mins or 15 mins CPU Load, it is warning. If 1 min's CPU LOAd spike 5% compare to 5 mins or 15 mins CPU Load, it is critical. However I received following code error, I google it and... (10 Replies)
Discussion started by: alvintiow
10 Replies

2. UNIX for Dummies Questions & Answers

Invalid arithmetic operator

Hi experts, I'm facing trouble with the below bash script, any help is appreciated #!/usr/bin/bash .. if (( "${date1}" > "${l_date1}" )) then echo "success" else echo "nothing" fi the variable date1 contains 08/06/2013 and l_date1 contains 10/08/2013 this small script to... (6 Replies)
Discussion started by: parpaa
6 Replies

3. Shell Programming and Scripting

Help with String concatenation

I have a script which is migrated from AIX to Linux & now while running it is no able to concatenate string values The string concatenation step under while loop is not displaying desired result Please find below the piece of code: while read EXT_FILE ; do EXT_FILE=$EXT_FILE.ext.sent echo... (7 Replies)
Discussion started by: PreetArul
7 Replies

4. Shell Programming and Scripting

String concatenation

Hi, I have two files. cat file.txt a b c d cat file1.txt j k l m I need the output as a:j (12 Replies)
Discussion started by: nareshkumar522
12 Replies

5. Shell Programming and Scripting

checking variables + arithmetic operator help

i'm trying to make a script to simply add numbers together for example i have a file script file called add add 1 2 3 4 5 15 however i want the user to put at least 3 numbers so i did this if then echo "please enter more than two numbers" exit 1 fi but it's telling me i have... (3 Replies)
Discussion started by: el3ctr0nic47
3 Replies

6. UNIX for Dummies Questions & Answers

syntax error: invalid arithmetic operator

hi, i have a bash script that i want to receive a a string from another bash file. But because the string has a dot in the middle it gives me an error. The error is in this line: let valor=$1 and the value passed is rules.txt the error is: let: valor=rules.txt: syntax error: invalid... (2 Replies)
Discussion started by: limadario
2 Replies

7. Shell Programming and Scripting

String Concatenation

Hi All, I need to concatenate the values in the array into a variable. Currently the code is : for (( i=1 ; i <= $minCount ; i++ )) do var="${var}""${sample_file}" done The output is : /tmp/1/tmp/2/tmp/3/tmp/4/tmp/5/tmp/6/tmp/7/tmp/8/tmp/9/tmp/10 I need a space between... (1 Reply)
Discussion started by: sh_kk
1 Replies

8. Shell Programming and Scripting

String concatenation with spaces

Hi, I have a variable $ID=40 and I need to build a string like 40 40 40 40 40 40 so repeating ID 'n' times separated by spaces. Any help? Thanks Sarah (2 Replies)
Discussion started by: f_o_555
2 Replies

9. Shell Programming and Scripting

Help concatenation string and variable

Hello, in my script i have this lines of code in a while cycle: .. let j=i+1 t_prod_$i = `cat myfile.csv | grep world | cut -d ";" -f$j` let i+=1 ... So if i try an echo $t_prod_$i at the end of the cycle i cannot see the right value obtained by `cat myfile.csv | grep world |... (5 Replies)
Discussion started by: drain
5 Replies

10. UNIX for Dummies Questions & Answers

string concatenation

my input file contains thousands of lines like below 234A dept of education 9788 dept of commerce 8677 dept of engineering How do i add a delimeter ':' after FIRST 4 CHARACTERS in a line 234A:dept of education 9788:dept of commerce 8677:dept of engineering (7 Replies)
Discussion started by: systemsb
7 Replies
Login or Register to Ask a Question