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

Frank Shearar frank.shearar at gmail.com
Fri Jun 20 08:14:42 UTC 2014


On 20 June 2014 01:17, Eliot Miranda <eliot.miranda at gmail.com> 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 :-(

That's an odd-looking construction- why would you want to
conditionally define the function, as opposed to define the function
with the conditional inside?

function quietmd5 () {
  if [ "$OS" = Darwin ]; then
    /sbin/md5 -q "$1";
  else
    /usr/bin/md5sum "$1"| sed 's/ .*$//';
  fi
}

??

frank

> --
> best,
> Eliot


More information about the Vm-dev mailing list