#!/bin/bash -i # A script to assist in exposing user-defined shell functions # (not aliases) to utilities that only have access to the $PATH. # # Usage: create a symlink somewhere on your $PATH such that the # name of the link is "run_" plus the name of the function to # be invoked. # # For example, if you define a function named update_confs # and wish to expose this to other non-shell processes that don't know # about shell functions, you would create on your $PATH a # symlink named run_update_confs, and when you execute that file, # this script will execute the update_confs function, passing through # any arguments that were submitted. # # If the function has output, it will be written to a file # in /tmp/out (if the directory exists and is writable) with the # name of the function appended with '.out'. # # In the above example, output would be written to # /tmp/out/update_confs.out. # # If the directory does not exist or is not writable, output # goes to /dev/null. # The name of the link, which is also the name of the function # to be executed. command="$(basename $0)" if [ ${#command} -lt 5 -o \ "$(echo ${command} | cut -c 1-4)" != "run_" ]; then cat < ${out_file} Cannot find function with name "${command}". Exiting.. EOF exit 1 fi echo "${command} $*" ${out_file} ${command} $* > ${out_file} 2>> ${out_file} exit 0