Re: security considerations for: set x dir/[*] dir/*



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 ...
done
#v-

or:

#v+
set -- "$dir/"*
while [ $# -gt 0 ]; do
[ -e "$1" ] || continue
# ... do whatever you want with $1 ...
shift
done
#v-



--
Stéphane
.



Relevant Pages

  • Re: bit operations and parity
    ... Only one shift is needed per iteration, so there are no questions about whether the processor has a barrel shifter. ... exercise for the reader. ... (Extending it to float and double is left ...
    (comp.lang.java.programmer)
  • Re: circular shifting a vector/matrix - Problem
    ... corrCoef = zeros(1, numColMatrix01); ... for shiftSize = 1:numColMatrix01, ... Are you sure you want to shift like this (iteration 1, 1 shift, ...
    (comp.soft-sys.matlab)
  • security considerations for: set x dir/[*] dir/*
    ... The following steps for the iteration are: ... contents of $is under the control of an attacker (and this shell ...
    (comp.unix.shell)
  • Re: bit operations and parity
    ... Mayeul wrote in ... The table could be computed offline and stored in the source code, ... for the shift at the end of each iteration. ...
    (comp.lang.java.programmer)
  • Re: Position of title changes in each loop. Why?
    ... So I expect titleposition to be the ... You are shifting the title slightly up in each iteration. ... I assume you are plotting on the same axis in each loop. ... You only need to shift it once. ...
    (comp.soft-sys.matlab)