waspsoft.com


Home > Syntax Error > Bash For Loop Syntax Error Operand Expected

Bash For Loop Syntax Error Operand Expected

Contents

Your script revised using better modern bash practice: #!/bin/bash k=0 #this loop is just for being sure array is loaded while ((k<=${#hitEnd[@]})); do echo "hitEnd is: ${hitEnd[k]} and hitStart is: ${hitStart[k]}" more stack exchange 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 more hot questions question feed lang-bsh about us tour help blog chat data legal privacy policy work here advertising info mobile contact us feedback Technology Life / Arts Culture / Recreation Seems unlikely but sometimes it happens. http://waspsoft.com/syntax-error/bash-if-syntax-error-operand-expected.html

Careful, though, if you export COLUMNS AND set the variables to a wrong value inside your script then 'tput' will also report wrong values. asked 2 years ago viewed 21117 times active 10 months ago Linked 0 syntax error: operand expected (error token is “- ”) Related 2bash script error let: -: syntax error: operand Convince people not to share their password with trusted others Subtraction with a negative result Force Microsoft Word to NEVER auto-capitalize the name of my company Is there a good way MTK358 View Public Profile View LQ Blog View Review Entries View HCL Entries Find More Posts by MTK358 View Blog 08-14-2011, 04:41 PM #9 ta0kira Senior Member Registered: Sep

Bash Syntax Error Operand Expected (error Token Is )

How does the pilot control the Dassault Rafale? INPUT1=/tmp/dir1 INPUT2=/tmp/dir2 INPUT3=/tmp/dir3 for i in 1 2 3 do echo $(INPUT$i) done When I run this script, tho output is: syntax error: operand expected (error token is "/tmp/dir1 bash scripts UPDATE: The reason for not using is mostly because they are easier to miss. –tusharkant15 Apr 9 '15 at 16:37 | show 9 more comments 4 Answers 4 active oldest votes

MTK358 View Public Profile View LQ Blog View Review Entries View HCL Entries Find More Posts by MTK358 View Blog 08-14-2011, 03:17 PM #7 crts Senior Member Registered: Jan more hot questions question feed lang-sh about us tour help blog chat data legal privacy policy work here advertising info mobile contact us feedback Technology Life / Arts Culture / Recreation When explicitly starting a script with an executable, use bash, not sh; in your example: bash /usr/local/src/backupcheck.sh Alternatively, with the shebang as is and if you want to be able to Expr: Syntax Error Force Microsoft Word to NEVER auto-capitalize the name of my company Activate Hearthstone season chest cards?

Does mean=mode imply a symmetric distribution? Syntax Error Operand Expected (error Token Is = ) Meaning of Guns and ghee Did Donald Trump call Alicia Machado "Miss Piggy" and "Miss Housekeeping"? Then what you intended as the contents of the second backquote expression it sees outside of backquotes, and sees the following as a second backquote expression: ` done echo "The factorial On THE other hand or on another hand?

That was quick! –user862489 Jul 28 '11 at 4:35 @Laurent, reverted as it doesn't fit in with the rest of the answer (replace x by y). –jman Aug 28 Integer Expression Expected 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! Click Here to receive this Complete Guide absolutely free. Like a forgotten $ when wanting to compare the value of COLUMNS?

  1. Now I know my ABCs, won't you come and golf with me?
  2. bash unix share|improve this question asked Nov 24 '13 at 16:03 shoham 3372417 Why the downvote? –Blue Ice Nov 24 '13 at 16:27 Check also the -gt
  3. Were slings used for throwing hand grenades?
  4. for s in '/tmp/dir '{1..3}' with spaces'; do echo "$s" done That prints: /tmp/dir 1 with spaces /tmp/dir 2 with spaces /tmp/dir 3 with spaces And if your goal is really
  5. Skipping directly to level 4 Can I use an HSA as investment vehicle by overcontributing temporarily?
  6. 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
  7. When taking passengers, what should I do to prepare them?

Syntax Error Operand Expected (error Token Is = )

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 The following example illustrates that a declared integer is not treated as a string. $ n=6/3 $ echo $n 6/3 $ declare -i n $ n=6/3 $ echo $n 2 When Bash Syntax Error Operand Expected (error Token Is ) By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Bash (error Token Is ") Limit involving exponentials and arctangent without L'Hôpital GTIN validation Why did companions have such high social standing?

Read through the linked duplicates to identify how to fix it. weblink Thanks. The characters $ and ` retain their special meaning within double quotes. How rich can one single time travelling person actually become? Syntax Error In Expression Error Token Is

asked 1 year ago viewed 283 times active 1 year ago Linked 40 In bash, is it possible to use an integer variable in the loop control of a for loop? Browse other questions tagged linux bash for-loop or ask your own question. However, it is strange that it works now. http://waspsoft.com/syntax-error/bash-syntax-error-operand-expected.html appearing in double quotes is escaped using a backslash.

How to pluralize "State of the Union" without an additional noun? Bash Let Unix & Linux Stack Exchange works best with JavaScript enabled Unix & Linux Forums > Top Forums > Shell Programming and Scripting Member Name Remember Me? Best wishes ...

Code: $ echo $COLUMNS 128 Excellent, the environment variable is set Code: $ cat col.sh #!/bin/bash echo $COLUMNS $ ./col.sh $ What the???

Will the medium be able to last 100 years? Remove advertisements Sponsored Links ygemici View Public Profile Find all posts by ygemici #3 05-23-2011 lakshmikanthe Registered User Join Date: May 2011 Last Activity: 4 October 2013, 5:47 Instead of a while loop, why not a for loop? Unary Operator Expected Thus, effectively, the if command's body will be executed if the backup drive exists.

It's as if the COLUMNS varaible is smaller than the actual screen width. what can i add to my code to successful execution of my script. ---------- Post updated at 03:23 PM ---------- Previous update was at 10:03 AM ---------- any one their to How's the CMD trip bonuses from extra legs work? his comment is here Although, in terms of syntax, indirect expansion as presented above is nearly as simple as doing it with an array, you still may wish to use an array because: It may

Don't you mean this instead? #!/bin/bash # define arrays hitStart[@] and hitEnd[@]... # define array array[@] #this loop is just for being sure array is loaded for ((k=0;k<${#hitEnd[@]};++k)); do echo "hitEnd I get the same error with ((l<=)). tput is part of ncurses, and should be installed on all systems. Try this instead: grep $BACKUP_DRIVE /etc/fstab | awk '{print $2}' if [[ $? -ne 0 ]] ; then ...

Don't use bash. And use indentation. –muru Apr 9 '15 at 16:02 2 I'm voting to close this question as off-topic because problems due to typos are hardly useful. –muru Apr 9 '15 Limit involving exponentials and arctangent without L'Hôpital How to handle spending money for extended trip to Europe? more hot questions lang-bsh about us tour help blog chat data legal privacy policy work here advertising info mobile contact us feedback Technology Life / Arts Culture / Recreation Science Other

How to increase the population growth of the human race Force Microsoft Word to NEVER auto-capitalize the name of my company Can a creature benefit from differently typed speed bonuses all The best solution I could find until now is to use 'tput' to get the size of the terminal. Rosa Parks is a [symbol?] for the civil rights movement? We are still treating the variable as a string.

up vote 4 down vote Use round parenthesis for numeric computations: num1=$((num1 + num2)) share|improve this answer edited Nov 24 '15 at 17:58 BoltClock♦ 381k939341043 answered Nov 24 '13 at 16:10