LDP/LDP/guide/docbook/abs-guide/list-glob.sh

32 lines
753 B
Bash
Raw Normal View History

2001-07-10 14:25:50 +00:00
#!/bin/bash
2012-11-27 14:56:18 +00:00
# list-glob.sh: Generating [list] in a for-loop, using "globbing" ...
# Globbing = filename expansion.
2001-07-10 14:25:50 +00:00
echo
for file in *
2005-10-21 13:31:28 +00:00
# ^ Bash performs filename expansion
#+ on expressions that globbing recognizes.
2001-07-10 14:25:50 +00:00
do
ls -l "$file" # Lists all files in $PWD (current directory).
2005-10-21 13:31:28 +00:00
# Recall that the wild card character "*" matches every filename,
#+ however, in "globbing," it doesn't match dot-files.
2001-07-10 14:25:50 +00:00
2005-10-21 13:31:28 +00:00
# If the pattern matches no file, it is expanded to itself.
# To prevent this, set the nullglob option
#+ (shopt -s nullglob).
# Thanks, S.C.
2001-07-10 14:25:50 +00:00
done
echo; echo
for file in [jx]*
do
2001-09-04 13:27:31 +00:00
rm -f $file # Removes only files beginning with "j" or "x" in $PWD.
2001-07-10 14:25:50 +00:00
echo "Removed file \"$file\"".
done
echo
exit 0