gnu-parallel encrypting files with spaces or special characters?

2

I'm trying to encrypt a bunch of files with the code below:

find . -name "*.vi" | sort | parallel --gnu -j 4 --workdir "$PWD" '
    echo "Encrypting {/.} ..."
    gpg -r user@myemail.com -o "/tank/test/{/.}.gpg" -e "{}"
';

This works fine, but only if the filenames have no spaces nor special characters (! or ') in them. Other than re-naming all the files, is there a way to make this code work?

Weekender

Posted 2015-05-29T08:25:45.137

Reputation: 45

Answers

2

It looks like too much quoting. Remember that GNU Parallel assumes {} is being parsed directly by the shell. Try removing "" around {} and {/.}:

# Avoid typing --gnu ever again
echo '--gnu' >> ~/.parallel/config

find . -name "*.vi" | sort |
  parallel echo Encrypting {/.} ...";" gpg -r user@myemail.com -o /tank/test/{/.}.gpg -e {}

Ole Tange

Posted 2015-05-29T08:25:45.137

Reputation: 3 034

Works! The resulting filenames have their spaces replaced by "" but that's no problem, i can just run a rename command after that. Thanks man! – Weekender – 2015-05-29T20:05:09.103

Then you have not removed enough ". Remove more. Remember {} and {/.} should never be inside " or '. – Ole Tange – 2015-05-29T20:45:04.630