Arithmetic syntax error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Arithmetic syntax error
# 1  
Old 10-05-2016
Arithmetic syntax error

Hello,

I am new to shell scripting and getting the error "arithmetic syntax error" on line 55 of my script.

Below is line 55 and 56

Code:
    Backup=$ (( $Year*365+$Day ))
if [[ $PrevHostname = '' ]] then PrevHostname=$Hostname; PrevBackup=$Backup

Error:

Code:
./mksysbChk.ksh: line 56:  *365+as : arithmetic syntax error

Any help to fix this will be appreciated.


Thanks,

Last edited by Don Cragun; 10-05-2016 at 05:48 PM.. Reason: Add CODE tags.
# 2  
Old 10-05-2016
Code:
(( Backup = Year * 365 + Day ))

# 3  
Old 10-05-2016
Sorry, I did not get that. Remove the $ signs and include Backup with the brackets?

---------- Post updated at 03:51 PM ---------- Previous update was at 03:34 PM ----------

After the suggested edit; I get the below error
Code:
syntax error at line 56: `((' unexpected


Last edited by rbatte1; 10-06-2016 at 05:17 AM.. Reason: Added CODE tags for output/error
# 4  
Old 10-05-2016
You can't have a space between the $ and the ((. So, change:
Code:
    Backup=$ (( $Year*365+$Day ))

to:
Code:
    Backup=$(( $Year*365+$Day ))

Inside an arithmetic expansion (i.e., $((expression))), shell variable expansions that expand to numeric strings can be specified using $variable_name or variable_name, so the above can also be specified as:
Code:
    Backup=$(( Year*365+Day ))

and get the same results.
# 5  
Old 10-05-2016
The *365+as in the error message is a bit suspect. What be the contens of $Day?
# 6  
Old 10-05-2016
Code:
let Backup=$Year*365+$Day

# 7  
Old 10-05-2016
Code:
Day=`date|cut -c9-10`                          # into Month(Mmm), Day(##) & Year(##)

---------- Post updated at 04:06 PM ---------- Previous update was at 04:02 PM ----------

Backup=$Year*365+$Day works. Thanks

However, I get an email failure message;
Code:
Final-Recipient: RFC822; hasn318@****.com
Action: failed
Status: 5.0.0
Diagnostic-Code: SMTP; 550 Not permitted
Last-Attempt-Date: Wed, 5 Oct 2016 17:03:40 -0400


Last edited by Don Cragun; 10-05-2016 at 06:14 PM.. Reason: Add CODE and ICODE tags.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh Arithmetic syntax error while comparing decimal numbers

Hello, I am having a problem when i execute following script on RHEL 6.4. Same script works fine on another machine where I have same version of RHEL and KSH. Below is the rpm and RHEL version. ossvm12(0)> rpm -qa | grep ksh ksh-20100621-19.el6.x86_64 ossvm12(0)> cat... (7 Replies)
Discussion started by: Adithya Gokhale
7 Replies

2. Shell Programming and Scripting

IF section problem. syntax error: unexpected end of file error

Hello, I have another problem with my script. Please accept my apologies, but I am really nooby in sh scripts. I am writing it for first time. My script: returned=`tail -50 SapLogs.log | grep -i "Error"` echo $returned if ; then echo "There is no errors in the logs" fi And after... (10 Replies)
Discussion started by: jedzio
10 Replies

3. Shell Programming and Scripting

floating point arithmetic operation error

I am writing a script in zsh shell, it fetchs a number from a file using the awk command, store it as a variable, which in my case is a small number 0.62000. I want to change this number by multiplying it by 1000 to become 620.0 using the command in the script var2=$((var1*1000)) trouble is... (2 Replies)
Discussion started by: piynik
2 Replies

4. 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

5. Shell Programming and Scripting

Receiving error: ./ang.ksh[35]: 0403-057 Syntax error at line 116 : `done' is not expected.

Hi All I am quite new to Unix. Following is a shell script that i have written and getting the subject mentioned error. #!/bin/ksh #------------------------------------------------------------------------- # File: ang_stdnld.ksh # # Desc: UNIX shell script to extract Store information.... (3 Replies)
Discussion started by: amitsinha
3 Replies

6. Shell Programming and Scripting

ksh-script "arithmetic syntax error" comparing strings

Hi all, Iīve already searched the forum but canīt find what i am doing wrong. I am trying to compare two variables using ksh under red hat. The error I get is: -ksh: .: MDA=`md5sum /tmp/ftp_dir_after_transfer | cut -d' ' -f1 ` MDB=`md5sum /tmp/ftp_dir_before_transfer | cut -d' ' -f1 `... (3 Replies)
Discussion started by: old_mike
3 Replies

7. AIX

nim mksysb error :/usr/bin/savevg[33]: 1016,07: syntax error

-------------------------------------------------------------------------------- Hello, help me please. I am trying to create a mksysb bakup using nim. I am geting this error, how to correct it ? : Command : failed stdout: yes stderr: no... (9 Replies)
Discussion started by: astjen
9 Replies

8. UNIX for Dummies Questions & Answers

awk Shell Script error : "Syntax Error : `Split' unexpected

hi there i write one awk script file in shell programing the code is related to dd/mm/yy to month, day year format but i get an error please can anybody help me out in this problem ?????? i give my code here including error awk ` # date-month -- convert mm/dd/yy to month day,... (2 Replies)
Discussion started by: Herry
2 Replies

9. UNIX for Dummies Questions & Answers

arithmetic syntax

okay, I'm a complete beginner, and I keep getting stuck on the syntax here. I want to write a script where I read the current time as minutes and seconds, convert the minutes to seconds, and add the two, then redirect the output to a file. the command takes two arguments, which will also be... (1 Reply)
Discussion started by: paprbagprincess
1 Replies
Login or Register to Ask a Question