Error Token Is Bash
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 posting bash operand expected error token ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the syntax error near unexpected token bash 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: syntax error near unexpected token bash function Sign up syntax error: operand expected (error token is “> ” 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
Bash Syntax Error Near Unexpected Token Done'
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 + 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 bash syntax error near unexpected token echo' + 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.2k1859103 asked Nov 15 '15 at 16:03 luke davis 54 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 meant a1=$num1 instead of num1=$a1, but you don't need a1 at all; you can just use $num1. The same holds for a2 and num2. share|improve this answer answered Nov 15 '15 at 16:09 chepner 138k12122195 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Not the an
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 bash syntax error near unexpected token (' ubuntu company Business Learn more about hiring developers or posting ads with us Stack Overflow
Bash Syntax Error Near Unexpected Token Else'
Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7
Bash Syntax Error Near Unexpected Token Fi'
million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Bash- syntax error: operand expected up vote 4 down vote favorite 1 I have two arrays that I want to http://stackoverflow.com/questions/33721744/syntax-error-operand-expected-error-token-is 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 it suffers from the lack of the second variable, but I mentioned earlier I do echo the values and everything seems to http://stackoverflow.com/questions/13672022/bash-syntax-error-operand-expected 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]} expands to nothing (it is undefined). I get the same error with ((l<=)). You should write your for loop as: k=0 for ((l=${hitStart[0]};k<${#hitEnd[@]} && l<=${hitEnd[k]};l++)); do so as to always have an index k that corresponds to a defined field in the array ${hit
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 us Unix http://unix.stackexchange.com/questions/164966/line-4-5-syntax-error-operand-expected-error-token-is & Linux Questions Tags Users Badges Unanswered Ask Question _ Unix & Linux Stack Exchange is a question http://askubuntu.com/questions/769722/bash-12-08-value-too-great-for-base-error-token-08 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 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 syntax error subject line when trying to execute the below listed bash 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.6k21431 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 syntax error near /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|improve this answer answered Oct 30 '14 at 11:56 jimmij 20.1k64267 BTW, you can omit $ inside parentheses: echo $((x+y)) –jimmij Oct 30 '14 at 12:04 why is this behaviour noticed in Ubuntu reading variables separately resolved the issue however i am not sure why it works in RHEL and CentOS but not in ubuntu where in we have to read the variables one at a time –snoopy Oct 30 '14 at 13:37 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Not the answer you're looking for? Browse other questions tagged ubuntu or ask your own question. asked 1 year ago viewed 3696 times acti
communities company blog Stack Exchange Inbox Reputation and Badges sign up log in tour help Tour Start 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 us Ask Ubuntu Questions Tags Users Badges Unanswered Ask Question _ Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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 Bash 12 - 08 Value too great for base (error token “08”) up vote 2 down vote favorite So, I'm trying to calculate 12-08 (not 12-8) and get the following error: let: 08: value too great for base (error token is "08") Here's the sample code: first=12 second=08 if [[ ($first > $second) ]]; then let fin=first-second else let fin=second-first fi P.S Sorry about the spacings bash scripts share|improve this question edited May 9 at 11:15 terdon♦ 42.1k686153 asked May 9 at 11:03 EmberSpirit 172 3 See Why does bash thinks that 010 is 8? –steeldriver May 9 at 11:11 add a comment| 1 Answer 1 active oldest votes up vote 7 down vote If you precede a number by 0, bash treats the number as octal. As octal is base 8 with digits ranging from 0 to 7, 08 is out of range for octal. Now you have two options to do decimal calculation: Omit preceding 0: $ echo $(( 12 - 8 )) 4 Explicitly mention base as decimal by 10#: $ echo $(( 12 - 10#08 )) 4 share|improve this answer edited May 9 at 15:14 Community♦ 1 answered May 9 at 11:11 heemayl 43.8k780134 2 @cat it's also used in i) the shebang line (#!/bin/bash); ii) string manipulation (var="foo"; echo ${var#f}); iii) the $# variable; iv) the !# variable and a few other fringe cases here and there :) Have a look at man bash | grep '#'. –terdon♦ May 9 at 16:01 @cat: # only starts a comment when used at the beginning of a word. –deltab May 9 at 16:31 At the beginning of a word; e.g. echo foo#bar #baz will output foo#bar but not #baz, because the latter starts a comment. –deltab May 9 at 19:52 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Not the answer you're look