Oops! This is not bash! Anyway...
The cause of the process is the continuation of the main thread, something in the meantime does not affect this. I browse 10k image directories and invert duplicates. I put the comparison code in the function and subprocess. It's very fast.
The way to return the value is to create a channel, direct the value to it, and then read the pipe: (Warning! The following code probably does not work, it just shows the working channel)
mkfifo pipe moved=0 # Use imageMagick 'compare' to find files with zero difference: comPare () { if [[ ! $(compare -metric AE $1 $2) ]]; then mv $2 moved; echo 1 > pipe; else echo 0 > pipe fi } # For every file in the dir, compare it to every other one: for file1 in $( ls *.bmp | head -n $(( $( ls *.bmp | wc -l) - 1)); do for file2 in $( ls *.bmp | tail -n $(( $( ls *.bmp | wc -l) - 1)); do comPare file1 file2 & moved=$(( $(cat pipe) + 1 )) done done rm pipe echo "Moved $moved files"
The only problem so far is that I am working on a USB drive, and permissions stop me from creating a channel. Besides...
gryphonB
source share