Find the answer to your Linux question:
Results 1 to 6 of 6
Tried using bash 3.1's "for" command and it keeps flagging my semicolons: for (( m=0 ) ; ( $m<=20 ) ; ( m=$m+1 )) do ... done It says it ...
  1. #1
    Linux User
    Join Date
    Mar 2008
    Posts
    287

    Using bash's for command

    Tried using bash 3.1's "for" command and it keeps flagging my semicolons:

    for (( m=0 ) ; ( $m<=20 ) ; ( m=$m+1 ))
    do
    ...
    done
    It says it is a syntax error so I put spaces on either side of all of them to no avail.
    Can someone help? I just do not see it.

  2. #2
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    if you just want to go to 20
    Code:
    for i in {0..19}
    do
      # do something
    done

  3. #3
    Linux Newbie
    Join Date
    Jul 2008
    Posts
    181
    Code:
    for (( m=0; $m < 10; m++ )); do echo $m; done

  4. #4
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    Minor comment: the remaining "$" can also be eliminated:
    Code:
    for (( m=0; m < 10; m+=2 )); do echo $m; done
    0
    2
    4
    6
    8
    cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  5. #5
    Just Joined!
    Join Date
    Sep 2008
    Posts
    20
    Quote Originally Posted by drl View Post
    Hi.

    Minor comment: the remaining "$" can also be eliminated:
    Code:
    for (( m=0; m < 10; m+=2 )); do echo $m; done
    0
    2
    4
    6
    8
    cheers, drl
    This way is so nice.

    I also have another way:

    Code:
    for i in `seq 0 2 9`;
    do
      echo $i;
    done

  6. #6
    Linux User
    Join Date
    Mar 2008
    Posts
    287

    Using bash's for command

    Thanks, burschik, you seen my too many parans. How I get my head so wired?? Appreciate all who helped.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...