Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Exec not outputting result to function

How do I get the result of the find to be used by the function? I keep getting blank results.

#!/bin/bash

#functions
function codec_scan () {

 echo "paremter 1 is this: $1" # >> $fulllog

}

#exporting
export -f codec_scan

#Main Code
find . -type f \( -name "*.avi" -o -name "*.AVI" -o -name "*.m4v" -o -name "*.mkv" -o -name "*.mp4" -o -name "*.MP4" \) -exec bash -c codec_scan \"\{}\" \;

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

\"\{}\" is literal characters " with {} inside. It’s a sole {}. Nothing before it, nothing after it. Unless you want to add a literal " characters.

It’s bash -c 'script...'. The arguments that follow are arguments to the script, not to the function. Each function has its own $1 $2 ... positional arguments, they are separate to script. And they arguments to bash -c start from $0, not from $1, see man bash, it is like bash -c 'script..' <$0> <$1> <$2> ...

You want:

find ....  -exec bash -c 'codec_scan "$@"' bash {} \;

Do not use function in bash. Just codec_scan() {. See https://wiki.bash-hackers.org/scripting/obsolete

You may be interested in -iname.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading