Search code examples
shgnu-parallel

Is there a way to achieve the same in "gnu parallel" with less nested quoting?


Although this script works, I am not happy about the excess of nested quoting, which makes the script very fragile and difficult to modify. The script consists basically of parallel followed by a filter test argument followed by command arguments.

#!/bin/sh
uhrzeit_0=$(date --rfc-3339=ns) ; uhrzeit="$uhrzeit_0 $(echo "$uhrzeit_0" | sha512sum)"   ;
find ./* -maxdepth 30 -type f -print0 | parallel --null  \
"mimetype --output-format %m {} | grep video > /dev/null \
&&  echo -en '\nSeparator: ' && echo -e $uhrzeit \
&& echo -n 'md5sum: ' && md5sum {} && echo -n 'du -h: ' \
&& du -h {} && ffmpeg -loglevel quiet -i {} -f ffmetadata - " > Film_metadata.txt

Solution

  • #!/bin/bash
    uhrzeit_0=$(date --rfc-3339=ns)
    uhrzeit="$uhrzeit_0 $(echo "$uhrzeit_0" | sha512sum)"
    
    doit() {
      F="$1"
      mimetype --output-format %m "$F" | grep video > /dev/null &&
        echo -en '\nSeparator: ' &&
        echo -e $uhrzeit &&
        echo -n 'md5sum: ' &&
        md5sum "$F" &&
        echo -n 'du -h: ' &&
        du -h "$F" &&
        ffmpeg -loglevel quiet -i "$F" -f ffmetadata -
    }
    export -f doit
    
    find ./* -maxdepth 30 -type f -print0 |
      parallel --null doit > Film_metadata.txt