You are not logged in.
I'd like to use a find | parallel function combo to:
1) Find all directories
2) Enter the directories and run a predefined function
#!/bin/bash
bcue() {
shntool cue *.flac > foo.cue
shntool join *.flac
}
find -type d | parallel cd {} ; bcue
Running this doesn't work as expected. It simply runs the bcue function from the dir from which I run the script. How can I call the function after I cd into the directory using parallel?
Last edited by graysky (2012-07-03 23:32:34)
CPU-optimized Linux-ck packages @ Repo-ck • AUR packages • Zsh and other configs
Offline
I've never used parallel, but it seems you'd want to put {} around everything right of the pipe.
But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner
Offline
Because it's being interpreted as two commands:
parallel cd {};
bcue
You need to invoke a shell in order to change directories before executing something. Something like (quoting problems notwithstanding)
parallel bash -c "cd {}; bcue"
This still won't actually work because the inner invocation of bash doesn't inherit the definition of bcue, but it's a step in the right direction. Consider embedding the two shntool invocations directly, or maybe using a different approach altogether. I'd use Perl personally, but that's probably at least a little bit because my bash sucks.
Offline
You might want to look at the -execdir function that find has too.
Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest
Offline
Yes, but -execdir won't do the operations in parallel...
However, you could instead do something like
find -type d -execdir sh -c "cd {}; bcue &" \;
which will start the operations represented by 'bcue' in the background, which may or may not be exactly the same thing as the original version with parallel. But you still can't use it as written because the new "inner" shell doesn't know anything about the bcue function. Consider making a script out of it. Better yet, consider making it a script that takes a directory name as an argument; then you could just do
find -type d | parallel $script {}
(making some guesses about the correct invocation of parallel based on what you wrote; I don't use it myself.)
Offline
Nice discussion, guys. Solution:
$ cat ~/bin/bincue
#!/bin/bash
[[ -z "$1" ]] && echo "Must give a dir!" && exit 1
cd "$1"
shntool cue *.flac > "$1".cue
shntool join *.flac
$ cd /mnt/music
$ find . -type d | parallel bincue {}
Last edited by graysky (2012-07-03 23:37:57)
CPU-optimized Linux-ck packages @ Repo-ck • AUR packages • Zsh and other configs
Offline