Reputation: 31
odd question I am playing around with the Linux find command and can successfully find a script file, I then want to run it without spawning a new shell is that possible?
example:
$ find ~ iname script.sh -exec ls -s {} -exec bash {} +
this successfully runs the script but I don't want to spawn a new shell, is it possible to just run the script?
Upvotes: 0
Views: 1429
Reputation: 295403
Do you mean you want to source the scripts you find into your current shell? If so:
while IFS= read -r -d '' scriptname; do
printf '%s\n' "$scriptname" >&2
source "$scriptname"
done < <(find ~ -iname script.sh -print0)
If you merely mean that you want to avoid more than one interpreter being involved when running them as subprocesses:
find ~ -iname script.sh -exec ls -sh '{}' ';' -exec '{}' ';'
...quoting {}
isn't necessary for bash, but it's a habit to be in if one's code may be used from zsh.
Upvotes: 2