Reputation: 321
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
Reputation: 123608
You don't need a function here. Try:
find . -name "*.pyc" -exec sh -c "pycdc {} > {}_dec" \;
Upvotes: 3
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
Reputation: 11365
Try this:
find . -path '*.pyc' -exec bash -c pycdc "$0" >"$0"_dec {} \;
Upvotes: 0