user2054758
user2054758

Reputation: 321

How recursively call a command on linux shell

I would like to run a command(pycdc) on each files of all sub-folders

#!/bin/sh
uncompyle () {
pycdc "$1" >"$1"_dec
}
export -f uncompyle

find . -type f -name '*.pyc' -exec bash -c 'uncompyle "$0"' {} \;

But i got the error:

Bad MAGIC!
Could not load file ./file/my.pyc

How is the correct code?

Upvotes: 0

Views: 180

Answers (3)

devnull
devnull

Reputation: 123608

You don't need a function here. Try:

find . -name "*.pyc" -exec sh -c "pycdc {} > {}_dec" \;

Upvotes: 3

konsolebox
konsolebox

Reputation: 75548

It would be safer if you use process substitution and run it on a loop instead since your function won't be exported through find.

while read -r F; do
    uncompyle "$F"
done < <(exec find . -type f -name '*.pyc')

Upvotes: 1

Srini V
Srini V

Reputation: 11365

Try this:

find . -path '*.pyc' -exec bash -c pycdc "$0" >"$0"_dec {} \;

Upvotes: 0

Related Questions