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 :-(
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
On 20 June 2014 01:17, Eliot Miranda eliot.miranda@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
On Jun 20, 2014, at 1:14 AM, Frank Shearar frank.shearar@gmail.com wrote:
On 20 June 2014 01:17, Eliot Miranda eliot.miranda@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?
well, squint at it and its almost object-oriented, "here are the implementations of functions on macos; here are the implementations of functions on Linux". And if the use count is high it's more efficient. And it reads nicer. You'd be at least mildly offended to see such if-then-else code in Smalltalk right?
function quietmd5 () { if [ "$OS" = Darwin ]; then /sbin/md5 -q "$1"; else /usr/bin/md5sum "$1"| sed 's/ .*$//'; fi }
??
frank
-- best, Eliot
On 20 June 2014 15:42, Eliot Miranda eliot.miranda@gmail.com wrote:
On Jun 20, 2014, at 1:14 AM, Frank Shearar frank.shearar@gmail.com wrote:
On 20 June 2014 01:17, Eliot Miranda eliot.miranda@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?
well, squint at it and its almost object-oriented, "here are the implementations of functions on macos; here are the implementations of functions on Linux". And if the use count is high it's more efficient. And it reads nicer. You'd be at least mildly offended to see such if-then-else code in Smalltalk right?
I think it reads the same: I mean, it's bash, so by definition "stinky" is a suitable adjective.
Efficiency's a valid point though: that hadn't occurred to me at all. It's like a macro (in the lisp sense) that gives you a platform-specific function.
But I usually think of this quote I saw somewhere: "if it's more than 10 lines of bash rewrite it in a proper language". Sadly, that's not an acceptable comeback for the launcher: "oh, so to run this general purpose language I need this other general purpose language installed already? Why don't I just go use that one?"
frank
function quietmd5 () { if [ "$OS" = Darwin ]; then /sbin/md5 -q "$1"; else /usr/bin/md5sum "$1"| sed 's/ .*$//'; fi }
??
frank
-- best, Eliot
On Thu, Jun 19, 2014 at 5:17 PM, Eliot Miranda eliot.miranda@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
this works:
test "$OS" = Darwin && function quietmd5 () { /sbin/md5 -q "$1"; } test "$OS" != Darwin && function quietmd5 () { /usr/bin/md5sum "$1"| sed 's/ .*$//'; }
On Sun, Jun 22, 2014 at 12:54 PM, btc@openinworld.com wrote:
Eliot Miranda wrote:
On Thu, Jun 19, 2014 at 5:17 PM, Eliot Miranda eliot.miranda@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
this works:
test "$OS" = Darwin && function quietmd5 () { /sbin/md5 -q "$1"; } test "$OS" != Darwin && function quietmd5 () { /usr/bin/md5sum "$1"| sed 's/ .*$//'; }
-- best, Eliot
nice technique. cheers -ben
This one goes to my cheat sheet :-)
Phil
On 22.06.2014, at 05:41, Eliot Miranda eliot.miranda@gmail.com wrote:
On Thu, Jun 19, 2014 at 5:17 PM, Eliot Miranda eliot.miranda@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
this works:
test "$OS" = Darwin && function quietmd5 () { /sbin/md5 -q "$1"; } test "$OS" != Darwin && function quietmd5 () { /usr/bin/md5sum "$1"| sed 's/ .*$//'; }
Or shorter:
[ "$OS" = Darwin ] && function quietmd5 () { /sbin/md5 -q "$1"; } [ "$OS" = Darwin ] || function quietmd5 () { /usr/bin/md5sum "$1"| sed 's/ .*$//'; }
Best -Tobias
vm-dev@lists.squeakfoundation.org