bug-bash
[Top][All Lists]
Advanced

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

Re: Problem with a "for"


From: Bob Proulx
Subject: Re: Problem with a "for"
Date: Tue, 7 Jul 2009 15:11:48 -0600
User-agent: Mutt/1.5.18 (2008-05-17)

tirengarfio wrote:
> IPS={89.17.206.180,89.17.206.185,89.17.206.186,89.17.206.187}

Check the value that you assigned using echo.

  $ echo "$IPS"
  {89.17.206.180,89.17.206.185,89.17.206.186,89.17.206.187}

Notice that brace expansion hasn't occurred in variable assignment.

In the bash manual it says:

       A variable may be assigned to by a statement of the form

              name=[value]

       If value is not given, the variable is assigned the null
       string.  All values undergo tilde expansion, parameter and
       variable expansion, command substitution, arithmetic
       expansion, and quote removal (see EXPANSION below).

Notice that it doesn't say that the value undergoes brace expansion.
This feature originated in csh and csh didn't perform brace expansion
on variable assignment either.

You can do what you want by using echo and process substitution.

  IPS=$(echo {89.17.206.180,89.17.206.185,89.17.206.186,89.17.206.187})

However I don't really see the point here.  It seems easier simply to
use a normal variable string assignment.

  IPS="89.17.206.180 89.17.206.185 89.17.206.186 89.17.206.187"

That seems the simplest and best way to do this.

> for i in ${IPS}
> do
> nmap -p 22 {IPS}
> done

Again using echo here is very useful.

  $ for i in ${IPS}
  > do
  >   echo nmap -p 22 {IPS}
  > done
  nmap -p 22 {IPS}

You didn't have a dollar sign there.  But actually you wanted to
say $i instead.

Hope this helps,
Bob




reply via email to

[Prev in Thread] Current Thread [Next in Thread]