Bash Syntax Error Operand Expected
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 bash syntax error operand expected (error token is ) Us Learn more about Stack Overflow the company Business Learn more about hiring bash int developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the
(( I Syntax Error Operand Expected (error Token Is )
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 Bash- syntax error: operand expected
Syntax Error Operand Expected (error Token Is = )
up vote 4 down vote favorite 1 I have two arrays that I want to loop in. I construct those properly and before going into for loop, I do echo them to be sure everything is ok with arrays. But when I run the script, it outputs an error: l<=: syntax error: operand expected (error token is "<=" I consulted the mighty Google and I understood bash (error token is "<= ") it suffers from the lack of the second variable, but I mentioned earlier I do echo the values and everything seems to be OK. Here is the snippet.. #!/bin/bash k=0 #this loop is just for being sure array is loaded while [[ $k -le ${#hitEnd[@]} ]] do echo "hitEnd is: ${hitEnd[k]} and hitStart is: ${hitStart[k]}" # here outputs the values correct k=$((k+1)) done k=0 for ((l=${hitStart[k]};l<=${hitEnd[k]};l++)) ; do //this is error line.. let array[l]++ k=$((k+1)) done The variables in the for loop are echoed correctly but for loop won't work.. where am I wrong? # as gniourf_gniourf answered: "... At some point, k will reach the value ${#hitEnd[@]}, and this is exactly when hitEnd[k] is not defined and expands to an empty string! Bang!" meaning error output is displayed not at the beginning of the loop, but when k has a greater value than array's indices, pointing an index that array does not include... linux bash for-loop share|improve this question edited Dec 2 '12 at 19:08 asked Dec 2 '12 at 17:52 teutara 3671722 add a comment| 2 Answers 2 active oldest votes up vote 4 down vote accepted That's because at some point ${hitEnd[k]} exp
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
Syntax Error In Expression (error Token Is
Learn more about Stack Overflow the company Business Learn more about hiring developers invalid arithmetic operator (error token is or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack expr: syntax error 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 syntax error: operand expected (error token is “> http://stackoverflow.com/questions/13672022/bash-syntax-error-operand-expected ” up vote 0 down vote favorite ./ex6.bash: 줄 10: ((: > : syntax error: operand expected (error token is "> ") And this is my code: #!/bin/bash printf "Input first number => " read num1 printf "Input second number => " read num2 num1=$a1 num2=$a2 if (( $a1>$a2 )) then while [ $a1==$a2 ]; do let "a1 = $a1 - 1" let "a2 = $a2 + http://stackoverflow.com/questions/33721744/syntax-error-operand-expected-error-token-is 1" if (( $a1==$a2 )) then printf " $num2 ~ $num1 mid point : $a1 \n" break elif (( $((a1 -1))==$a2 )) then printf " $num2 ~ $num1 mid point : $a1 \n" break fi done else while [ $a1==$a2 ]; do let "a1 = $a1 + 1" let "a2 = $a2 - 1" if (( $a1==$a2 )) then printf " $num1 ~ $num2 mid point : $a1 \n" break elif (( $((a1 -1))==$a2 )) then printf " $num1 ~ $num2 mid point : $a1 \n" break fi done fi What's wrong and how do I fix it? I don't know what to do. bash unix share|improve this question edited Nov 15 '15 at 16:04 Doorknob 33.1k1859103 asked Nov 15 '15 at 16:03 luke davis 13 1 You're missing lots and lots of spaces. Also, you never assign anything to a1 or a2. –Doorknob Nov 15 '15 at 16:04 Please fix any errors suggested by shellcheck.net before continuing. –chepner Nov 15 '15 at 16:07 add a comment| 1 Answer 1 active oldest votes up vote 1 down vote You never set a value for a1, so the arithmetic statement (($a1>$a2)) expands to ((>)). Perhaps you mean
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings http://unix.stackexchange.com/questions/164966/line-4-5-syntax-error-operand-expected-error-token-is and policies of this site About Us Learn more about Stack Overflow 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 syntax error 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 line 4: 5 + : syntax error: operand expected (error token is “+ ”) up vote 1 down vote favorite noticing the error mentioned in the subject line when trying to execute the below listed bash (error token is script on Ubuntu (53-Ubuntu x86_64 x86_64 x86_64 GNU/Linux) #!/bin/bash read x y echo $(($x + $y)) However same runs perfectly on Redhat and CentOS. Please help me find why this is happening all OS's have bash version 4.3.11(1)-release ubuntu share|improve this question edited Oct 30 '14 at 11:40 steeldriver 13.2k21431 asked Oct 30 '14 at 11:34 snoopy 816 #!/bin/bash was used –snoopy Oct 30 '14 at 11:40 Please add the output of ls -l /bin/bash (on the failing OS). –John WH Smith Oct 30 '14 at 11:55 -rwxr-xr-x 1 root 0 1021112 Oct 7 19:22 /bin/bash –snoopy Oct 30 '14 at 13:38 add a comment| 1 Answer 1 active oldest votes up vote 1 down vote accepted It gives error because you provide only one input number, not two. In such case read assigns this number to variable x, but y will stay empty, so next line looks like echo $(($x + )). As we know operator + takes two operands, but here y (the second one) is missing, thus the error operand expected (error token is “+ ”). share|impr