Arithmetic Syntax Error In Ksh
Contents |
Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here. ksh if Search Forums Show Threads Show Posts Tag Search Advanced Search
Ksh Syntax Error Unexpected
Unanswered Threads Find All Thanked Posts Go to Page... unix and linux commands - unix shell ksh arithmetic comparison scripting ksh-script "arithmetic syntax error" comparing strings Shell Programming and Scripting Thread Tools Search this Thread Display Modes #1 10-14-2009
Arithmetic Syntax Error In Shell Script
old_mike Registered User Join Date: Oct 2009 Last Activity: 16 December 2009, 10:44 AM EST Posts: 5 Thanks: 0 Thanked 0 Times in 0 Posts 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 arithmetic syntax error bash hat. The error I get is: -ksh: .[123]: [: 75e245dfe25b753cfd69987a314adfe7: arithmetic syntax error Below are the lines of the script, line 123 is the if-line, MDA and MDB values are correct, near the brackets there is only one space: Code: MDA=`md5sum /tmp/ftp_dir_after_transfer | cut -d' ' -f1 ` MDB=`md5sum /tmp/ftp_dir_before_transfer | cut -d' ' -f1 ` if [ $MDA -eq $MDB ]; then echo "wrong" else echo "correct" fi Thanks for your support old_mike Last edited by old_mike; 10-14-2009 at 10:33 AM.. Remove advertisements Sponsored Links old_mike View Public Profile Find all posts by old_mike #2 10-14-2009 zaxxon code tag tagger Join Date: Sep 2007 Last Activity: 30 September 2016, 10:29 AM EDT Location: St. Gallen, Switzerland Posts: 6,481 Thanks: 158 Thanked 528 Times in 463 Posts To keep the forums high quality for all users, please take the time to format your posts correctly. First of all, use Code Tags when you post any code or data samples so others can easily
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
Ksh Math
the company Business Learn more about hiring developers or posting ads with us Unix
Expr Syntax Error In Shell Script
& Linux Questions Tags Users Badges Unanswered Ask Question _ Unix & 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 a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and http://www.unix.com/shell-programming-and-scripting/121329-ksh-script-arithmetic-syntax-error-comparing-strings.html rise to the top arithmetic syntax error in string compare up vote 2 down vote favorite I have 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 http://unix.stackexchange.com/questions/220333/arithmetic-syntax-error-in-string-compare 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 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
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 http://unix.stackexchange.com/questions/3648/why-am-i-getting-a-syntax-error-with-my-shell-arithmetic the company Business Learn more about hiring developers or posting ads with us Unix & Linux Questions Tags Users Badges Unanswered Ask Question _ Unix & 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 a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and syntax error rise to the top Why am I getting a syntax error with my Shell arithmetic? up vote 4 down vote favorite I have a problem with a linux shell script (sh). I'm trying to write a script that calculates combinations, but I think I get overflows when trying to calculate faculties. So, I'm trying another technique. In this technique I used this: a=`expr $var1 \* $var2 / $var3` This is giving errors, and apperently, arithmetic syntax error I can't do this: a=`expr ($var1 \* $var2) / $var3` because this gives errors as well. How do I do it? shell share|improve this question edited Oct 29 '11 at 4:13 John 2001310 asked Oct 30 '10 at 20:09 3sdmx 12114 What errors are you getting? That works in bash at least –Michael Mrozek♦ Oct 30 '10 at 20:20 expr: syntax error –3sdmx Oct 30 '10 at 20:21 add a comment| 2 Answers 2 active oldest votes up vote 6 down vote You can use dc for arbitrary precision results: precision=4 var1=3 var2=4 var3=5 a=`echo "$precision k $var1 $var2 * $var3 /p" | dc` should work in about every Unix variant since 1977 or so. If you know you have gnu dc available the more concise a=`dc -e "$precision k $var1 $var2 * $var3 /p"` can be used. share|improve this answer answered Oct 30 '10 at 20:36 msw 7,5501829 add a comment| up vote 2 down vote For your example with parens, you must escape them too: expr \( $var1 + $var2 \) / $var3 (and don't omit the spaces, or expr will complain). In bash you can also use built-in arithmetic expansion like this: echo $(( ($var1+$var2)/$var3 )) And for infix calculations there's bc (while dc is for reverse-polish notation). share|improve this answer answe