*ping* BASH scripters - Linux

This is a discussion on *ping* BASH scripters - Linux ; This should be the easiest thing on earth, and it used to work. I must be screwing up somewhere but I dont know where Slackware 12, here's the script: ---------------- #!/bin/bash LENGTH=0 while [ ${LENGTH} -le 2 ] do /usr/games/fortune ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: *ping* BASH scripters

  1. *ping* BASH scripters

    This should be the easiest thing on earth, and it used to work. I must
    be screwing up somewhere but I dont know where

    Slackware 12, here's the script:

    ----------------
    #!/bin/bash

    LENGTH=0
    while [ ${LENGTH} -le 2 ]
    do
    /usr/games/fortune -aes > /home/jason/.signature
    LENGTH=`/usr/bin/wc -l /home/jason/.signature | /usr/bin/cut -d " " -f1`
    done
    echo >> /home/jason/.signature
    echo "http://www.websterscafe.com" >> /home/jason/.signature

    exit 0
    ----------------

    As you can see by my sig, the script is letting stuff longer than 2
    lines through the while loop. WTF?

    --
    There was a young lady named Astor
    Who never let any get past her.
    She finally got plenty
    By stopping twenty,
    Which certainly ought to last her.

    http://www.websterscafe.com

  2. Re: *ping* BASH scripters

    Handover Phist wrote:

    > This should be the easiest thing on earth, and it used to work. I must
    > be screwing up somewhere but I dont know where
    >
    > Slackware 12, here's the script:
    >
    > ----------------
    > #!/bin/bash
    >
    > LENGTH=0
    > while [ ${LENGTH} -le 2 ]
    > do
    > /usr/games/fortune -aes > /home/jason/.signature
    > LENGTH=`/usr/bin/wc -l /home/jason/.signature | /usr/bin/cut -d " " -f1`
    > done
    > echo >> /home/jason/.signature
    > echo "http://www.websterscafe.com" >> /home/jason/.signature
    >
    > exit 0
    > ----------------
    >
    > As you can see by my sig, the script is letting stuff longer than 2
    > lines through the while loop. WTF?


    Faulty/reversed logic.

    In pseudo code your script is...

    Set counter to 0
    While counter is less than 3
    Get some random lines from fortune
    Count the lines
    Set counter to number of lines

    So this will loop, getting lines and counting them, for as long as
    thre are *two or less* lines spit out by fortune. Only if fortune
    returns three or more lines will it terminate and finish generating
    your final .signature file.

    One obvious fix would be to adjust your starting point and reverse the
    equality test...

    #!/bin/bash

    LENGTH=25
    while [ ${LENGTH} -ge 3 ]
    do ....

    That should loop as long as fortune returns three or more lines,
    only terminating and creating your final .signature if it sees 2 lines
    or less.

  3. Re: *ping* BASH scripters

    JoB :
    > Handover Phist wrote:
    >
    >> This should be the easiest thing on earth, and it used to work. I must
    >> be screwing up somewhere but I dont know where
    >>
    >> Slackware 12, here's the script:
    >>
    >> ----------------
    >> #!/bin/bash
    >>
    >> LENGTH=0
    >> while [ ${LENGTH} -le 2 ]
    >> do
    >> /usr/games/fortune -aes > /home/jason/.signature
    >> LENGTH=`/usr/bin/wc -l /home/jason/.signature | /usr/bin/cut -d " " -f1`
    >> done
    >> echo >> /home/jason/.signature
    >> echo "http://www.websterscafe.com" >> /home/jason/.signature
    >>
    >> exit 0
    >> ----------------
    >>
    >> As you can see by my sig, the script is letting stuff longer than 2
    >> lines through the while loop. WTF?

    >
    > Faulty/reversed logic.
    >
    > In pseudo code your script is...
    >
    > Set counter to 0
    > While counter is less than 3
    > Get some random lines from fortune
    > Count the lines
    > Set counter to number of lines
    >
    > So this will loop, getting lines and counting them, for as long as
    > thre are *two or less* lines spit out by fortune. Only if fortune
    > returns three or more lines will it terminate and finish generating
    > your final .signature file.
    >
    > One obvious fix would be to adjust your starting point and reverse the
    > equality test...
    >
    > #!/bin/bash
    >
    > LENGTH=25
    > while [ ${LENGTH} -ge 3 ]
    > do ....
    >
    > That should loop as long as fortune returns three or more lines,
    > only terminating and creating your final .signature if it sees 2 lines
    > or less.


    Usenet: A simple method of advertising ones idiocy . Thanks, I knew it
    was something simple.

    --
    Prope mare erat tubulator
    Qui virginem ingrediebatur.
    Dessine ingressus
    Audivi progressus:
    Est mihi inquit tubulator.

    http://www.websterscafe.com

+ Reply to Thread