First i need to find all scripts directly under /DIR that end with ".sh" extension except "noallow.sh". That can be done with:
find /DIR -maxdepth 1 -name "*.sh"|grep -v "noallow.sh"
Now i want to run all the files output from the previous command.
The following code:
for filename in $(find /DIR -maxdepth 1 -name "*.sh"|grep -v "noallow.sh")
do
/DIR/${filename}
done
Can do the job. But i want to know can this whole thing be done by using find only with exec {}.
It can even be done without find:
ksh (and zsh with kshglob enabled):
for s in "$path"/!(noallow).sh; do "$s"; done
For bash you should enable extended glob with:
shopt -s extglob
Regarding your question for find/exec:
find "$path" -maxdepth 1 -name '*.sh' ! -name 'noallow.sh' -exec {} \;
dir=/path/to/wherever
for script in "$dir"/*.sh
do
case $script in "$dir"/noallow.sh) continue ;; esac
"$script"
done
--others had posted the same--
find "$path" -maxdepth 1 -name '*.sh' ! -name 'noallow.sh' -exec {} \;
Now can i echo/print the name of the script before running it and all this using find command?
find "$path"/*.sh ! -name noallow.sh -print -exec {} \;