Arithmetic Syntax Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or arithmetic syntax error in shell script posting ads with us Unix & Linux Questions Tags Users Badges Unanswered Ask Question _ Unix xsibackup arithmetic syntax error & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes ksh 1800 cp arithmetic syntax error a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top arithmetic syntax error in string compare up vote 2 down vote favorite I have
Ksh Script Arithmetic Syntax Error
written a shell script which takes file name as parameter e.g user/test.txt. I want to make this file parameter optional if user does not wish to provide file name he/she can give as "None" Inside script I'm just checking if filename parameter contains "None" if [ $filename -eq "NONE" ];then cmd; fi When "None" is passed as parameter script works fine but when user/test.txt is passed I get below error message which I don't want to print on console arithmetic syntax error Can invalid arithmetic operator somebody help ? shell shell-script test share|improve this question edited Aug 5 '15 at 22:22 Gilles 368k666671117 asked Aug 5 '15 at 13:23 chhaya vishwakarma 210411 consider using bash's argument handling. It will help you be more consistent with other programs. –richard Aug 5 '15 at 13:28 3 Not part of this problem, but I'd put quotes around that variable ("$filename") in case, e.g., you end up with spaces in there. –goldilocks Aug 5 '15 at 13:36 1 @goldilocks, spaces or any character in$IFS, or wildcard characters. Funny how the quotes are put where they're not needed ("NONE") and not where they're needed (typical beginner mistake as that's true that it's counter-intuitive to anyone used to other kinds of languages). Note that [ itself is a glob character, though because it's not matched in a single word (or as a special case for zsh), it doesn't need to be quoted. –Stéphane Chazelas Aug 5 '15 at 14:26 add a comment| 1 Answer 1 active oldest votes up vote 7 down vote accepted [ bla bla bla ] is equivalent to test bla bla bla. From man test STRING1 = STRING2 the strings are equal STRING1 != STRING2 the strings are not equal INTEGER1 -eq INTEGER2 INTEGER1 is equal to INTEGER2 Therefore you need = not -eq. share|improve this answer edited Aug 5 '15 at 13:43 answered Aug 5 '15 at 13:26 richard 5,25311234 1 Ah!! I did silly mistake ..thanks for your
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company syntax error invalid arithmetic operator (error token is .0 ) Business Learn more about hiring developers or posting ads with us Unix & Linux Questions
Syntax Error Invalid Arithmetic Operator (error Token Is .5 )
Tags Users Badges Unanswered Ask Question _ Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD
Arithmetic Syntax Error Bash
and other Un*x-like operating systems. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Arithmetic http://unix.stackexchange.com/questions/220333/arithmetic-syntax-error-in-string-compare Syntax Error when running a script in RedHat OS up vote 0 down vote favorite I am encountering a problem when I try to run a script in RedHat OS. I get an arithmetic syntax error. Now here's the script that I am trying to run: #!/bin/ksh echo "" echo " = K+WA ="; WA_PORT="`cat /usr/kplushome/entities/Standalone/config/kondor.active |grep PORTAL_PORT|cut -d '&' -f 2`" #== Checking Tomcat of WebAccess printf "%25s" Tomcat touch /usr/kplushome/entities/Standalone/config/webaccess/WebaccessDomainTomcat/bin/tomcat-*.pid PID=`cat /usr/kplushome/entities/Standalone/config/webaccess/WebaccessDomainTomcat/bin/tomcat-*.pid` if [[ $PID http://unix.stackexchange.com/questions/263332/arithmetic-syntax-error-when-running-a-script-in-redhat-os = "" ]];then echo " x 0" else PSPID=`/bin/ps -eo pid | grep -w $PID` if [[ $PSPID -eq $PID ]];then /bin/ps -ef | grep $PID | grep -v grep | awk 'NR==1 {print " = "$8 $9 $10 $11 $12 $13 $14 $15}' else echo " x 0" fi fi PORT_STATUS=`netstat -an | grep ${WA_PORT} | grep LISTEN | perl -pe "s/^.+\n/LISTENING/g;"` PORT_STATUS=${PORT_STATUS:="NOT LISTENING!!!"} echo " Port ${WA_PORT}/TCP = ${PORT_STATUS}" cd /usr/kplushome/entities/Standalone/config/webaccess/WebaccessServer/etc (PATH=/usr/ucb:$PATH; ./checkall.sh;) | perl -pe "s,^, ,g;" echo "" Problem is I don't see anything wrong with my line 15 as I don't see any rule from unix that was violated for it to have an arithmetic syntax error, or am I missing something? May I ask for any advice from you experts? Any help would be much appreciated. Thank you. linux shell-script scripting share|improve this question edited Feb 16 at 5:08 asked Feb 15 at 8:23 Francis 32 1 Could be that any of $PSPID or $PID is empty at line 15 at script runtime? –coffeMug Feb 15 at 8:28 that I am not sure, is there a way for me to check whether line 15 is empty at script runtime or not? please help, thank you! –Francis Feb 16 at 3:27 Put an echo at line 14: echo "PSPID is:$PSPID and PID is:$PID". Something like that. –coffeMug
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with http://stackoverflow.com/questions/34211368/arithmetic-syntax-error-with-shell-script us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Arithmetic syntax error with shell script up vote 0 down vote favorite I am trying to call the function "warn" if the calculation is TRUE. I am still not quite comfortable with the syntax, would like some tips on how to syntax error fix the last line. if [ "$noproc" -gt 0 ]; then echo "WARNING: NoProc at $noproc for $process processes." >> $log elif [ "$max" -ge 11 ]; then [ $(($max - $total)) -lt 6 && [ $idle -le $(($max \* 0.25 | bc -l)) ] ] | warn $total $process $max $idle The error I get: line 97: [: missing ` ] ' bash shell unix share|improve this question asked Dec 10 '15 at 20:43 AbysmalCode 33 2 Consider using ShellCheck. It will arithmetic syntax error give you a clearer explanation for the parser error. –kojiro Dec 10 '15 at 20:49 Thanks alot ! Looks like a great tool ! –AbysmalCode Dec 10 '15 at 21:04 If this really is bash (as tagged), and your script starts with #!/bin/bash rather than #!/bin/sh, you've got much more flexible syntax available. ( max >= 11 )) is easier to read than [ "$max" -ge 11 ], after all. You could also use [[ ]] for an extended test context, which would let you use && internally (rather than having that result in the unexpected end of one command and beginning of another). –Charles Duffy Dec 10 '15 at 21:05 BTW, to explain why | is the wrong operator -- foo | bar runs both foo and bar at the same time, connecting the output of foo to the input of bar. By contrast, what you want here is to run bar only if foo completes successfully -- which a short-circuiting logical AND operator, &&, will do. –Charles Duffy Dec 10 '15 at 21:17 add a comment| 2 Answers 2 active oldest votes up vote 1 down vote accepted If your tagging for this question is correct and you're genuinely using bash (which is to say that your script starts with #!/bin/bash, or if not started via a shebang you use bash yourscript rather than sh yourscript), you might as well take advantage of it. # extended bash math syntax if (( (ma