Jim Meyering wrote: > Eric Blake wrote: >> According to Jim Meyering on 1/13/2010 3:19 AM: >>> I didn't account for that use case. >>> I wonder if there is some way to write/use a command-not-found >>> handler to automate the error-prone "add-$EXE-suffix" at run-time. >>> >>> If at all possible, I would like to avoid the invasive change >>> of adding the $EXE suffix to every just-built-binary invocation >>> in every test script. ...
I've found an even better way: Think of a set-up function that (when $EXEEXT is nonempty) iterates through the *.$EXEEXT executables in a specified directory... create_exe_shim_functions () { case $EXEEXT in '') return 0 ;; .exe) ;; *) echo "$0: unexpected value of $EXEEXT" 1>&2; return 1 ;; esac for file in *.$EXEEXT dummy; do case $file in dummy) continue;; esac # Remove the .$EXEEXT suffix. base=${file%.$EXEEXT} # Ensure that "$base" is not tainted (no space, backtick, semicolon, etc.) case $base in *[^-a-zA-Z0-9_.+]*) echo "$0: ignoring suspicious name: $base" 1>&2; continue;; esac # Create a function named $base whose sole job is to invoke $base.$EXEEXT, # assuming its containing dir is already in PATH. eval '$base() { $file "$@"; }' done return 0 } Now, run that function from each directory in PATH that might contain .exe binaries. Done. ;-) [untested]