Mailinglist Archive: opensuse (1264 mails)

< Previous Next >
Re: [opensuse] Quick question: how to call a script function from "find"?
On 2017-06-13 08:51, Bernhard Voelker wrote:
On 06/13/2017 05:38 AM, Carlos E. R. wrote:
The intention was to convert:

find /home/cer/Fusion/Videos/ -type d -exec sudo chown cer:cer '{}' \; find
/home/cer/Fusion/Videos/ -type d -exec
chmod u+r+w+x,g+w+x,o+r-w-x,+t '{}' \; find /home/cer/Fusion/Videos/ -type d
-exec sudo chown cer-g:cer '{}' \;
#setfacl -m u:wwwrun:rx /data/waterhoard/Fusion.uno/Videos

I'm not sure why you would want to chown to 'cer' and later to 'cer-g'.
This looks redundant to me.

Because on a second run of the script, the chmod would error on
directories already owned by "cer-g". Just a hack. The correct method
would be to check the permissions first, and change only if "incorrect".

Easier coding as compared to faster run - the time to do the correct
code doesn't seem worth it ;-)

And then I would have to investigate if find can do a search on all that
criteria. Probably so.

to a single "find". And calling a function in the same script seemed to me
the clearest way of doing it.

He, he - what about script recursion? ;-)

What? :-O

#!/bin/bash

if [ "$1" = '__do_action__' ]; then

shift 1 \
&& sudo chown cer:cer "$@" \
&& chmod u+r+w+x,g+w+x,o+r-w-x,+t "$@" \
&& sudo chown cer-g:cer "$@"
exit $?

fi

find /home/cer/Fusion/Videos/ -type d -exec "$0" __do_action__ '{}' +

(The above is untested, as I don't have users 'cer', 'cer-g', etc.,
but it should work.)

Oh :-O

Interesting!

$@? I don't know what that one does. [searching...]

@ Expands to the positional parameters, starting from one.
When the expansion occurs within double quotes, each parameter expands
to a separate word. That is, "$@" is equivalent to "$1" "$2" ... If the
double-quoted expansion occurs within a word, the expansion of the
first parameter is joined with the beginning part of the original
word, and the expansion of the last parameter is joined with the last
part of the original word. When there are no positional parameters,
"$@" and $@ expand to nothing (i.e., they are removed).


I don't quite see the difference with $* :-?


--
Cheers / Saludos,

Carlos E. R.
(from 42.2 x86_64 "Malachite" at Telcontar)

< Previous Next >
Follow Ups