commandlinefu.com is the place to record those command-line gems that you return to again and again.
You can sign-in using OpenID credentials, or register a traditional username and password.
Subscribe to the feed for:
If you want to operate on a set of items in Bash, and at least one of them contains spaces, the `for` loop isn't going to work the way you might expect. For example, if the current dir has two files, named "file" and "file 2", this would loop 3 times (once each for "file", "file", and "2"):
for ITEM in `ls`; do echo "$ITEM"; done
Instead, use a while loop with `read`:
ls | while read ITEM; do echo "$ITEM"; done
There is 1 alternative - vote for the best!
If you can do better, submit your command here.
You must be signed in to comment.