bash looping through a group of files alternatives to ls?
Hello there guys, i am trying to work on reports, nasty things :p
i am doing this thing Code:
for group in $(ls -1 grupos_*) |
Hi,
Is this what you are after: Code:
for group in grupos_* Hope this helps. |
thanks
yeah i found that yesterday forgot to put it on the forum, thanks a bunch for answering though
|
One other option which adds the flexibility of 'find' and avoids issues with spaces in file names:
Code:
find . -type f -name 'grupos_*' -print | while read group Stefan |
Check out these links for details on how to handle this issue:
http://mywiki.wooledge.org/ParsingLs http://mywiki.wooledge.org/DontReadLinesWithFor http://mywiki.wooledge.org/BashFAQ/001 In a nutshell, you have to be very careful how you handle the output of commands, particularly ones that generate lists of filenames. Word-splitting can cause all sorts of problems if you don't do it right. propofol's find solution is better, but still not completely safe as written. You should always use the -print0 option, and the corresponding syntax in the reading application. This is also detailed in the above links. Finally, beware of this common pipe subshell pitfall: http://mywiki.wooledge.org/BashFAQ/024 |
All times are GMT -5. The time now is 04:27 AM. |