• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 371
  • Last Modified:

While Loop

Is there a way to write the a while loop with a wildcard.  I can do the command with a For loop but would really like to make it work with a while loop.  For example:  
   cd /etc
   for x in b*
   do
   echo $x
   done

0
dorinda
Asked:
dorinda
1 Solution
 
dgrimesCommented:
ls b* 2>/dev/null | while read x
do
  echo $x
done

OR

while read x
do
  echo $x
done << -
`ls b* 2>/dev/null`
-

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now