From: Jeff Largent <jlargent@imagelinks.com>
To: linux-admin@vger.kernel.org
Subject: Re: bash question
Date: Thu, 01 Apr 2004 09:58:05 -0500 [thread overview]
Message-ID: <406C2DFD.9020603@imagelinks.com> (raw)
In-Reply-To: <200404010903.31878.fluca1978@virgilio.it>
And just to show another way:
#!/bin/bash
for i in `seq 1 10`; do
if [ $((${i} % 2)) != 0 ]; then
echo ${i}
fi
done
Luca Ferrari wrote:
> On Thursday 01 April 2004 02:45 Scott@Charter's cat walking on the keyboard
> wrote:
>
>
>>I can't get this bash script to work. It's suppose to print all odd
>>numbers from 1 to 10.
>>
>>#!/usr/bin/bash
>>
>>LIMIT=10
>>a=1
>>
>>while [ "$a" -le $LIMIT ]
>>do
>> if [ "$a" -eq $(1 3 5 7 9) ] <---------Something not right here.
>
>
> This is an awkard way to print all odd numbers, have a look at this:
>
> #!/bin/bash
>
> LIMIT=10
> a=1
>
> while test ${a} -lt ${LIMIT}
> do
> go=`expr ${a} % 2`
> if test ${go} -ne 0
> then
> echo "Odd number ${a}"
> fi
>
> a=`expr ${a} + 1`
>
> done
>
>
> exit 0
>
>
> In this example, if you change the LIMIT value to 100, the script will print
> you all odds numbers, while in your example you have to put numbers by your
> own. In perl it can result as:
>
> #!/usr/bin/perl
>
> $LIMIT=10;
> $a=1;
>
> while( $a < $LIMIT ){
> if( ($a % 2) !=0 ){
> print "Odd number $a\n";
> }
> $a++;
> }
>
> exit;
>
>
> Luca
>
>
--
Jeff Largent ImageLinks, Inc.
Sr System Admin Melbourne, Fl 32935
(321) 253-0011 fax: (321) 253-5559
next prev parent reply other threads:[~2004-04-01 14:58 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-04-01 0:45 bash question Scott@Charter
2004-04-01 7:03 ` Luca Ferrari
2004-04-01 14:58 ` Jeff Largent [this message]
2004-04-01 19:46 ` Chuck Harding
2004-04-01 22:53 ` Glynn Clements
2004-04-02 9:32 ` urgrue
2004-04-03 18:19 ` Nico Schottelius
2004-04-19 1:07 ` Joao Victor A. Di Stasi
2004-04-19 1:14 ` Joao Victor A. Di Stasi
2004-04-19 1:42 ` Stephen Samuel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=406C2DFD.9020603@imagelinks.com \
--to=jlargent@imagelinks.com \
--cc=linux-admin@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).