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

Bash For Loop Syntax Error Operand Expected

Contents

add a comment| 1 Answer 1 active oldest votes up vote 2 down vote accepted If you put set -xv in your script, you might be able to detect why there 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? Blank space must appear between it and its first argument. Code: #!/bin/bash COLS=$(tput cols) LINS=$(tput lines) echo $COLS echo $LINS This worked without having to export the environment variables. navigate here

If you unset COLUMNS LINES they will only get set the next time you resize the window (or set the values yourself). Similarly, it is required to pass the closing ] of a [ command as a separate command-line argument. up vote 3 down vote I agree that using an array as shown in other answers is a better way to solve the real task of the OP. You could use 'eval', however with modern versions of 'bash' the cleanest way imho is via an array input=( "/tmp/dir1" "/tmp/dir2" "/tmp/dir3" ) for i in {0,1,2}; do echo "${input[i]}"; done

Bash Syntax Error Operand Expected (error Token Is )

I'm aware of the difference between ' and ", but if you want create-prompt-infobar to be evaluated every time the prompt comes up it needs to be in single quotes. Don't use bash. The Woz Monitor Limit involving exponentials and arctangent without L'Hôpital Which requires more energy: walking 1 km or cycling 1 km at the same speed?

Symbolic comparison of recursive functions So sayeth the Shepherd Subtraction with a negative result Is the following extension of finite state automata studied? Meaning of Guns and ghee Did Donald Trump call Alicia Machado "Miss Piggy" and "Miss Housekeeping"? Visit the following links: Site Howto | Site FAQ | Sitemap | Register Now If you have any problems with the registration process or your account login, please contact us. Expr: Syntax Error you inspired me, and it works.. –teutara Dec 2 '12 at 18:34 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google

Adopt A Jet/Book So sayeth the Shepherd Why does Windows show "This device can perform faster" notification if I connect it clumsily? Syntax Error Operand Expected (error Token Is = ) To check if the input is a positive integer (only unsigned digits) you can use this awesome bash regex: [[ "$number" =~ ^[0-9]+$ ]] that checks if $numbercontains only digits. Why are some programming languages Turing complete but lack some abilities of other languages? is not removed.

Intuition behind Harmonic Analysis in Analytic Number Theory Finding a file starting with '-' dash Meaning of Guns and ghee Did Donald Trump call Alicia Machado "Miss Piggy" and "Miss Housekeeping"? Integer Expression Expected 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 And this should read the numbers and it should divide them up. appearing in double quotes is escaped using a backslash.

  • for i in {0,1,2}; works for me –Ubuntuser Sep 4 '13 at 7:10 @Ubuntuser How do you run the script? –Radu Rădeanu Sep 4 '13 at 7:12
  • it can be null ?
  • Why does bash think the file ends too soon, rather than the line?
  • Why do you use $(( )) instead of $[ ] like I was tought? –shoham Nov 24 '13 at 16:39 Well, either way is correct.
  • watch out how your variable k is always incremented, and remember that the test part in the for loop (i.e., the l<=hitEnd[k] part) is evaluated at each pass! –gniourf_gniourf Dec 2
  • With Bash and Korn shell, it is generally not needed.

Syntax Error Operand Expected (error Token Is = )

Is this safe to display MySQL query error in webpage if something went wrong? 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]}" Bash Syntax Error Operand Expected (error Token Is ) In summary: The original problem related to an unmatched ` in a backquote expression (and more generally, how to close a backquote expression and how newlines inside backquote expressions are handled Bash (error Token Is ") Using Map to convert Feet + Inches to Inches in a List of Lists On THE other hand or on another hand?

For example, BAZ=QUUX FOO='BAR $BAZ'; echo "$FOO" prints BAR $BAZ, not BAR QUUX.) If any of INPUTn might take on a value that echo would interpret as an option instead of check over here Adopt A Jet/Book Video displays in Star Wars Good way to explain fundamental theorem of arithmetic? I still wonder why it doesn't work, though. For option 1, the shebang needs to be #!/bin/bash, and the script should not be invoked as sh script-name.sh. Syntax Error In Expression Error Token Is

Reason: removed ambiguous sentence crts View Public Profile View LQ Blog View Review Entries View HCL Entries Find More Posts by crts 08-14-2011, 04:30 PM #8 MTK358 LQ 5k 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 Generally, you do not need [[ ... ]] for such tests at all, and instead simply use the command directly with if, possibly negated with !, and with output suppressed as his comment is here In this situation and many like it, the built-in !

Instead prefer $(). Bash Let When taking passengers, what should I do to prepare them? OK, I understand now.

Integral using residue theorem complex analysis Finding a file starting with '-' dash How does the pilot control the Dassault Rafale?

Are you using a pipe somewhere during the assignment process? The backslash preceding the ! Last edited by pludi; 05-23-2011 at 09:32 AM.. Remove advertisements Sponsored Links lakshmikanthe View Public Profile Find all posts by lakshmikanthe

#2 05-23-2011 ygemici Unary Operator Expected Code: $ cat coltest #!/bin/bash COLUMNS=3 # WRONG value LINES=4 # WRONG value COLS=$(tput cols) LINS=$(tput lines) echo $COLS echo $LINS $ ./coltest 80 24 $ export COLUMNS LINES $ ./coltest

Were slings used for throwing hand grenades? Code: # custom prompt function create-prompt-infobar { local i=0 if (($COLUMNS >= (${#PWD} + ${#?} + 11))); then echo -n "$PWD" for ((i=0; i<($COLUMNS-${#PWD}-${#?}-10); i++)); do echo ""; done echo -n However, it is possible to do math with shell script. http://onlinetvsoftware.net/syntax-error/bash-script-syntax-error-operand-expected.php Browse other questions tagged bash scripts or ask your own question.

MTK358 View Public Profile View LQ Blog View Review Entries View HCL Entries Find More Posts by MTK358 View Blog 08-14-2011, 02:37 PM #4 makyo Member Registered: Aug 2006 Is this safe to display MySQL query error in webpage if something went wrong? Success! As it appears, you will have to export COLUMNS and LINES before you can use them in a script.