how to use a bash function defined in your .bashrc with find -exec how to use a bash function defined in your .bashrc with find -exec bash bash

how to use a bash function defined in your .bashrc with find -exec


find ./ -name *.ogv -exec bash -c 'myfile {}' \;


I managed to run it perhaps more elegantly as:

function myfile { ... }export -f myfilefind -name out.ogv -exec bash -c '"$@"' myfile myfile '{}' \;

Notice that myfile is given twice. The first one is the $0 parameter of the script (and in this case it can be basically anything). The second one is the name of the function to run.


$ cat functions.bash#!/bin/bashfunction myecho { echo "$@"; }function myfile { file "$@"; }function mycat { cat "$@"; }myname=`basename $0`eval ${myname} "$@"$ ln functions.bash mycat$ ./mycat /etc/motdLinux tallguy 2.6.32-22-core2 ...$ ln functions.bash myfile$ myfile myfilemyfile: Bourne-Again shell script text executable$ ln functions.bash myecho$ myecho does this do what you want\?does this do what you want?$ 

where, of course, the functions can be a tad more complex than my examples.