[Vm-dev] conditionally define a function in sh/bash?

David T. Lewis lewis at mail.msen.com
Fri Jun 20 03:30:36 UTC 2014


On Thu, Jun 19, 2014 at 05:17:14PM -0700, Eliot Miranda wrote:
>  
> Hi All,
> 
>     I'm trying
> 
> if [ "$OS" = Darwin ]; then
>     function quietmd5 () { /sbin/md5 -q "$1"; }
> else
>     function quietmd5 () { /usr/bin/md5sum "$1"| sed 's/ .*$//'; }
> fi
> 
> but bash no like :-(
> -- 
> best,
> Eliot

Just a complete SWAG, but I would expect that functions would be probably
be declared in one pass, and execution happen in another pass. So I would
not expect to be able to compile the function at script execution time. Maybe
declare two functions, and call one or the other at runtime based on ${OS}.

Or write the script in perl. Or Smalltalk with CommandShell/OSProcess.

Dave


More information about the Vm-dev mailing list