From 27ad662b672cef5f3439ad32beda1f1b820ef600 Mon Sep 17 00:00:00 2001 From: Shawn Milochik Date: Sat, 15 Aug 2015 12:21:05 -0400 Subject: [PATCH] Added for and while loop info. --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index b398baa..1e12a7a 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,16 @@ Notes: - For running a command with privileges, use `sudo` (for root) or `sudo -u` (for another user). Use `su` or `sudo bash` to actually run a shell as that user. Use `su -` to simulate a fresh login as root or another user. +- Loops: To perform operations on many files or with multiple arguments, use `for` loops. Example: +```sh +for filename in *.txt; do echo "Found $filename"; done +``` + +- Loops for values with spaces (normal `for` loop will split filenames on spaces): + +```sh +find . -iname '*.txt' | while read filename; do cp "$filename" /tmp; done +``` ## Processing files and data