Results 1 to 3 of 3

Thread: Please help(regarding until loop and ! operator)

  1. #1
    Join Date
    Feb 2018
    Beans
    6

    Please help(regarding until loop and ! operator)

    A ! has been put to reverse the less than condition so it becomes a greater than condition It loops until a becomes greater than 10. Why am I getting the output only till 9? It should reach 11, when its greater than 10, right? How do I fix this?

    Code:

    #!/bin/bash

    a=0

    until [ ! $a -lt 10 ]
    do
    echo $a
    a = `expr $a + 1`
    done
    Output:
    0
    1
    2
    3
    4
    5
    6
    7
    8
    9

  2. #2
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Please help(regarding until loop and ! operator)

    But ! LT isn't a GT. The opposite of LT is GE (greater than or equal).

    I've never used an "until" in 25+ yrs of programming. Not once. Zero.

    Also, in bash, you can increment a counter using (a++). Much more efficient than the old-school way of calling an external program.

  3. #3
    Join Date
    Feb 2018
    Beans
    6

    Re: Please help(regarding until loop and ! operator)

    Thanks a lot.

Tags for this Thread

Bookmarks

Posting Permissions

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