Home > Syntax Error > Bash For Syntax Error Bad For Loop Variable

Bash For Syntax Error Bad For Loop Variable

Contents

Thanks everyone. –mkab Apr 11 '11 at 20:58 add a comment| 4 Answers 4 active oldest votes up vote 21 down vote accepted You probably run it with sh, not bash. share|improve this answer edited Sep 10 '11 at 2:00 Tom Zych 8,33662241 answered Apr 11 '11 at 21:25 David W. 70.2k15102220 add a comment| Your Answer draft saved draft discarded Can filling up a 75 gallon water heater tank without opening a faucet cause damage? Try bash test1.sh, or ./test1.sh if it's executable, but not sh test1.sh. Check This Out

Those are just examples that came to mind right now. –geirha May 20 '15 at 19:52 add a comment| 1 Answer 1 active oldest votes up vote 6 down vote accepted If you're writing a script that uses bash syntax, be sure to put #!/bin/bash at the top. ¹ Assuming you meant day+=5 where you wrote day+5, otherwise it's an infinite loop. Verbs of buttons on websites Which requires more energy: walking 1 km or cycling 1 km at the same speed? done In the above bash for command syntax, Before the first iteration, expr1 is evaluated.

Syntax Error Bad For Loop Variable Shell

It's always confused me why people feel the need to add them. If you want to use a C-style for loop in bash: for ((i=0;i<9;i++)); do echo "$i" done share|improve this answer edited Apr 22 at 23:18 that other guy 45k54070 answered Apr Therefore, even when sh is bash, "sh is not bash" still applies. –geirha May 20 '15 at 19:40 @geirha: On my Debian 6 system, /bin/sh is a symlink to Finding a file starting with '-' dash Is my workplace warning for texting my boss's private phone at night justified?

cd ~ ls * The following will display all the *.conf file that begins with either a, b, or, c or d under /etc directory. $ ls -1 /etc/[abcd]*.conf /etc/asound.conf /etc/autofs_ldap_auth.conf Why? UNIX is a registered trademark of The Open Group. Bash Syntax Error Invalid Arithmetic Operator To change your login shell use chsh command.

The bash version shipped with that ubuntu version should execute it without problems. If you double quote the variable in this for loop, the list of values will be treated as single value. Note: you want to echo $i. What does the "Phi" sign stand for in musical notation?

Provide an answer of your own, or ask Suman Mitra for more information if necessary. Bash Syntax Error Near Unexpected Token Then' asked 3 years ago viewed 5093 times active 1 year ago Visit Chat Linked 7 Writing a bash for-loop with a variable top-end Related 2882Can a Bash script tell which directory Replace #!/bin/sh with #!/bin/bash to make the shebang work. Ash is a relatively basic one designed for a small memory footprint and fast execution.

  1. The Bash command syntax is a superset of the Bourne shell command syntax. –Paolo Moretti Oct 26 '12 at 10:57 add a comment| up vote 9 down vote C-style for loop
  2. Switch to bash or ksh93 if you want to use that syntax.
  3. Bash has more features.
  4. even its not print echo $var also.

Bash Syntax Error Near Unexpected Token Done'

Problem? for num in {1..10..2} Link robin July 12, 2011, 9:50 am quote" Kamal Kishore" cat for12.sh for num in {1..10..2} do echo “Number: $num” done Above example is not working…. Syntax Error Bad For Loop Variable Shell In this form, the for statement executes the commands enclosed in a body, once for each item in the list. Bash Syntax Error Near Unexpected Token Else' Your code works in bash but not in sh Link ash July 7, 2014, 6:36 am nice articles, do you have any other posting for other loops like while and arithmetic

for num in {1..10..2} Link Pier July 12, 2011, 2:05 pm thanks Ramesh, I knew the "classic" bash syntax (but it is always good to pop up some old knowledge) but http://sovidi.com/syntax-error/bash-for-loop-syntax-error-operand-expected.php On THE other hand or on another hand? 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 Do you want to help us debug the posting issues ? < is the place to report it, thanks ! Bash Syntax Error Near Unexpected Token Fi'

You should not include the keyword "in" in the for loop. done exit 0 returns Syntax error: Bad for loop variable bash dash ash for share|improve this question edited May 17 '12 at 4:17 Mikel 28.8k768100 asked May 16 '12 at 18:32 My script still produces the above error, even though it is seemingly not supposed to. –Krøllebølle Oct 26 '12 at 10:39 copy-paste your script. this contact form Is the following extension of finite state automata studied?

i.e for loop will never get executed as shown in the example below. $ cat for3-wrong.sh i=1 for day in do echo "Weekday $((i++)) : $day" done $ ./for3-wrong.sh Mon Tue Bash Syntax Error Near Unexpected Token Do' How's the CMD trip bonuses from extra legs work? invoking via "bash test.sh" or "sh test.sh".

Thank you very must for posting those kinds of knowlege online.

The ";" doesn't make a difference if you have the do on the next line...just FYI. Ubuntu Logo, Ubuntu and Canonical Canonical Ltd. Is it possible to check for existence of member template just by identifier? Bash Syntax Error Near Unexpected Token Newline' Make sh a symbolic link to bash and then you can do sh ./test1.sh share|improve this answer answered Apr 12 '11 at 0:47 abc 5,3381357101 add a comment| up vote 0

How to extrude a face parallel to another? Join them; it only takes a minute: Sign up bash script - can't get for loop working up vote 3 down vote favorite Background Info: I'm trying to follow the example Hot Network Questions Rosa Parks is a [symbol?] for the civil rights movement? http://sovidi.com/syntax-error/bash-while-loop-syntax-error.php scripts share|improve this question edited Jan 6 '14 at 11:58 Florian Diesch 46.7k12105131 asked Jan 6 '14 at 11:56 Gaurav Rai 814 add a comment| 2 Answers 2 active oldest votes

Not the answer you're looking for? Please help.. Regards, Júlio. In a GNU C macro envSet(name), what does (void) "" name mean?

Don't specify the list; get it from the positional parameters If you don't specify the keyword "in" followed by any list of values in the bash for loop, it will use share|improve this answer edited Apr 4 '14 at 13:21 answered Apr 4 '14 at 13:16 Stephan Kulla 2,23511025 add a comment| Your Answer draft saved draft discarded Sign up or Which requires more energy: walking 1 km or cycling 1 km at the same speed? Results 1 to 7 of 7 Thread: script.sh: 1: Syntax error: Bad for loop variable Thread Tools Show Printable Version Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode

Link Aashish June 16, 2014, 4:40 pm Below code executed successfull but output will be not generated.. Problem Description My code looks like this: for i in {0..8..1} do echo "i is $i" tmpdate=$(date -d "$i days" "+%b %d") echo $tmpdate done When I run this code, the Dennis numbers 2.0 Which requires more energy: walking 1 km or cycling 1 km at the same speed? Ask Ubuntu works best with JavaScript enabled FAQ Forum Quick Links Unanswered Posts New Posts View Forum Leaders FAQ Contact an Admin Forum Community Forum Council FC Agenda Forum Governance Forum

Ultimately, I need it to work in both bash and sh. sh. actionparsnip (andrew-woodhead666) said on 2013-09-27: #8 If you mark the file as executable it will be treated as a script. 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

Adopt A Jet/Book spectral norm of block-wise sums of matrices What does the "Phi" sign stand for in musical notation? set +o nounset pe() { for i;do printf "%s" "$i";done; printf "%s\n"; } LC_ALL=C ; LANG=C ; export LC_ALL LANG pe ; pe "Environment: LC_ALL = $LC_ALL, LANG = $LANG" pe Ubuntu is run as a virtual machine using VMWare Player (shouldn't matter). –Krøllebølle Oct 26 '12 at 10:50 sh != bash .... –Karoly Horvath Oct 26 '12 at 12:22 This isn't Windows.

Adopt A Jet/Book Force Microsoft Word to NEVER auto-capitalize the name of my company How to map and sum a list fast?