Re: security considerations for: set x dir/[*] dir/*
- From: Stephane CHAZELAS <this.address@xxxxxxxxxx>
- Date: Sun, 3 Dec 2006 20:59:56 +0000
2006-12-03, 21:36(+01), Michal Nazarewicz:
Lasse Kliemann <stu33404@xxxxxxxxxxxxxxxx> writes:
set x ${dir?}/[*] ${dir?}/*
is a usefull construct to prepare an iteration over all files in a
directory ${dir}, taking into account the cases where ${dir} is empty
or contains a file with name *. I suspect that one can also use --
instead of the x, but I am not sure.
The following steps for the iteration are:
shift &&
case "${1?} ${2?}" in
${dir?}/\[\*\]\ ${dir?}/\*) return 0 ;;
*) : ;;
esac &&
shift &&
while test "$#" -ge 1; do
{
# ... do something with $1 ...
shift
} || return "$?"
done
???
#v+
for FILE in "$dir/"*; do
[ -e "$FILE" ] || continue
You may want do use
[ -e "$FILE" ] || [ -L "$FILE" ] || continue
instead.
Note that OPs solution has the advantage to work even if you
don't have execute permission to the directory (but then, you
will not be able to do much with the files in that dir).
# ... do whatever you want with $FILE ...shift
done
#v-
or:
#v+
set -- "$dir/"*
while [ $# -gt 0 ]; do
[ -e "$1" ] || continue
# ... do whatever you want with $1 ...
done
#v-
--
Stéphane
.
- References:
- security considerations for: set x dir/[*] dir/*
- From: Lasse Kliemann
- Re: security considerations for: set x dir/[*] dir/*
- From: Michal Nazarewicz
- security considerations for: set x dir/[*] dir/*
- Prev by Date: Re: security considerations for: set x dir/[*] dir/*
- Next by Date: Re: bash: processing files a chunk at a time / detecting stdin end of file
- Previous by thread: Re: security considerations for: set x dir/[*] dir/*
- Next by thread: Re: security considerations for: set x dir/[*] dir/*
- Index(es):
Relevant Pages
|