How to run multiple shell scripts in a directory?

when I want to execute some script shell on Unix (and let them say that I’m in the directory where the script is located), I simply type:

./someShellScript.sh

and when I want to "source" it (for example, run it in the current shell, and not in a new shell), I just type the same command with only "." (or with the equivalent of the "source" command) before it:

. ./someShellScript.sh


And now the hard part. When I want to execute "multiple" shell scripts (say, all files with the suffix .sh) in the current directory, I print:

find . -type f -name *.sh -exec {} \;

but "which command should be used for scripts with multiple" SOURCE "scripts in the directory" ?
I have tried this so far, but it has NOT worked:

find . -type f -name *.sh -exec . {} \;

and he just threw this error:

find: `.': Permission denied


Thank.

+3
source share
3 answers
for file in *.sh
do . $file
done
+13
source

Try the following version of Jonathan's code:

export IFSbak = $IFS;export IFS="\0"
for file in `find . -type f -name '*.sh' -print0`
do source "$file"
end
export IFS=$IFSbak

, , . ( ). find, , , , (, , , exec) .

, ( Jonathan's) , .

0

You can use find, and xargsfor this:

find . -type f -name "*.sh" | xargs -I sh {}
0
source

Source: https://habr.com/ru/post/1726628/


All Articles