LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Bash for loop (https://www.linuxquestions.org/questions/linux-software-2/bash-for-loop-781533/)

rhlee 01-11-2010 02:04 PM

Bash for loop
 
Hi again LQ,

My question arises from trying out something I found in another LQ thread.

I use csplit to split up a large file and I get file xx01, xx02 and so on. I use a for loop to loop through the files.

Code:

for f in "xx**"
do
        echo test
        echo $f
done

Instead of getting

Code:

test xx01 test xx02 test xx03 ...
I get

Code:

test xx01 xx02 xx03 ...
Am I doing something wrong here?


Richard

rweaver 01-11-2010 02:12 PM

This works for me.

Code:

for f in $(ls xx**); do echo "test $f"; done

pixellany 01-11-2010 02:17 PM

It's all in the quotes:
Code:

[mherring@mystical tst]$ ls
xxa  xxb  xxc  xxd
[mherring@mystical tst]$ for fil in *;do echo "test";echo $fil;done
test
xxa
test
xxb
test
xxc
test
xxd
[mherring@mystical tst]$ for fil in "*";do echo "test";echo $fil;done
test
xxa xxb xxc xxd
[mherring@mystical tst]$


rhlee 01-12-2010 03:59 AM

Quote:

Originally Posted by pixellany (Post 3822854)
It's all in the quotes

Yes it is, thank you.

It works now.


All times are GMT -5. The time now is 07:13 PM.