Code: Alles auswählen
# ln -s /etc/bash_aliases ~/.bash_aliases
#
MY_STUFF=/etc/bash_aliases
Fori ()
{
[[ $1 == "-h" || $1 == "--help" || ! $2 ]] &&
echo "
$FUNCNAME (loop_cnt cmd args...) | (cmd_to_loop arg_per_loop...) # for loop helper
" && return
local CMD=$1; shift
if [[ $CMD =~ ^[0-9]+$ ]]; then # CMD is counter
for i in `seq $CMD`; do
echo "===== $i."
"$@"
echo
done
else
if `type -P ${CMD%% *} >/dev/null`; then
for i in "$@"; do # CMD is command
echo "===== $i"
nice $CMD "$i"
[ $? -ge 128 ] && break
echo
done
else
for i in "$@"; do # CMD is alias
echo "===== $i"
(BASH_ENV=$MY_STUFF bash -c "$CMD \"$i\"")
[ $? -ge 128 ] && break
echo
done
fi
fi
}
Code: Alles auswählen
$ Fori 3 echo dreimal
===== 1.
dreimal
===== 2.
dreimal
===== 3.
dreimal
Code: Alles auswählen
$ Fori 'rar e' *part1.*
...