For loop - coping with an asterisk item


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting For loop - coping with an asterisk item
# 1  
Old 09-06-2007
Question For loop - coping with an asterisk item

How do you get a for loop to cope with one of the items being an asterisk?


for myResult in `echo "*"`
do
echo "$myResult"
done



The asterisk is returning a file listing in the PWD.

The same result can be got from:


for myResult in "*"
do
echo "$myResult"
done



How to I combat this? Smilie

Cheers.
# 2  
Old 09-07-2007
Probably, you need to disable pathname expansion. Use set -f. Something like

Code:
(set -f; for file in `echo "*"`; do echo $file; done; )

Login or Register to Ask a Question

Previous Thread | Next Thread

1 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to compare previous and current item in for loop in bash?

Hey, I am trying to compare formated login and logout dates from one user at a host which I have stored in a tmp directory in order to find out the total login time. I need to compare them in order to find overlapping intervals. At first I tried to store each log in and logo date in an array... (3 Replies)
Discussion started by: Mumu123
3 Replies
Login or Register to Ask a Question