Re: bash question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm going to presume that you want to search for a
specific set of numbers, and that the fact that the
fact that they're odd doesn't matter....

In that case, you'd have to use a for loop to seach
thru the list of 'important' values:

for $tval in 1 3 5 7 9; do
	if [ $a -eq $tval ]
	  then
		echo -n "$a "
	fi
done

As far as I know, there's no fast way to search for
one value in a list of candidates.

Scott@Charter 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.
    then
      echo -n "$a "
    fi

echo

let "a+=1"
done
echo; echo
exit 0


Can anyone figure out what I am doing wrong? Can I also see the same thing written in Perl?


--
Stephen Samuel +1(604)876-0426                samuel@xxxxxxxxxxx
		   http://www.bcgreen.com/~samuel/
   Powerful committed communication. Transformation touching
     the jewel within each person and bringing it to light.

-
: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Newbie]     [Audio]     [Hams]     [Kernel Newbies]     [Util Linux NG]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Device Drivers]     [Samba]     [Video 4 Linux]     [Git]     [Fedora Users]

  Powered by Linux