| 1 | #!/bin/bash |
| 2 | # list-glob.sh: Generating [list] in a for-loop, using "globbing" ... |
| 3 | # Globbing = filename expansion. |
| 4 | |
| 5 | echo |
| 6 | |
| 7 | for file in * |
| 8 | # ^ Bash performs filename expansion |
| 9 | #+ on expressions that globbing recognizes. |
| 10 | do |
| 11 | ls -l "$file" # Lists all files in $PWD (current directory). |
| 12 | # Recall that the wild card character "*" matches every filename, |
| 13 | #+ however, in "globbing," it doesn't match dot-files. |
| 14 | |
| 15 | # If the pattern matches no file, it is expanded to itself. |
| 16 | # To prevent this, set the nullglob option |
| 17 | #+ (shopt -s nullglob). |
| 18 | # Thanks, S.C. |
| 19 | done |
| 20 | |
| 21 | echo; echo |
| 22 | |
| 23 | for file in [jx]* |
| 24 | do |
| 25 | rm -f $file # Removes only files beginning with "j" or "x" in $PWD. |
| 26 | echo "Removed file \"$file\"". |
| 27 | done |
| 28 | |
| 29 | echo |
| 30 | |
| 31 | exit 0 |