Tuesday, June 10, 2008

Using korn shell functions with xargs

It's not easy to call fuctions with xargs. Even when they're exported they can't be invoked by xargs. But there's a way using eval like this.

#!/bin/ksh
function myecho_function
{
echo In myecho_function
echo $@
}

OLDIFS=$IFS
IFS='
'

for line in $(find ~ -type f -print | xargs echo myecho_function)
do
# this will call the function the minumum number times
eval $line
done

IFS=$OLDIFS

No comments: