On Thu, Aug 07, 2008 at 09:41:25AM +0100, David Lee wrote:
> On Wed, 6 Aug 2008, Dejan Muhamedagic wrote:
> 
> > On Wed, Aug 06, 2008 at 02:42:10PM +0100, David Lee wrote:
> > > > [...]
> > > > +       local rnd="$RANDOM"
> > > > [...]
> > >
> > > That "local ..." construction: is that a true Bourne feature?  In this
> > > "shellfuncs" area, we need to be as portable as possible, avoiding
> > > "bash-isms".  (I think we accept that some particular OCFs could well be
> > > "bash" these days, but these utility functions, shared across all OCFs,
> > > need to be Bourne.)
> > >
> > > [...]
> >
> > The "local" keyword is I think in the POSIX standard. Is there a
> > platform with shell which doesn't comply with the POSIX at least?
> 
> Sadly, yes.  For instance I have just tested 'sh' on Solaris 8, 9 and 10
> (Sun's currently supported releases): 'local' fails on all.

Pity.

> How to progress?  Conventions for such local variables (i.e. variables
> where the programmer's intention is to limit the scope to the block) to
> avoid namespace clashes include using a leading "_" in the name (avoid
> clash with 'main script' variables which don't use leading "_") and having
> the name somehow reflect the function name (avoid clash amongst different
> functions).  For instance:
> 
>    var1=XXX
>    var2=YYY
> 
>    my_function() {
>      _mf_v1=$1
>      _mf_v2=$2
>    }
> 
>    your_function() {
>      _yf_v1=$1
>      _yf_v2=$2
>    }
> 
> Pragmatically most sh-programming things are fine with such conventions;
> the quantities of potentially interacting functions are manageable by
> adoption of such conventions.

Right.

> Hope that helps.
> 
> Just to confirm:  I'm happy that individual OCFs be 'bash' (so long as
> they say "#!/bin/bash", not "!#/bin/sh").  And they can happily use
> 'local' withing themselves.  But what we're talking about here are the
> utility functions shared by all OCFs.  So (sadly but realistically) I
> think there has to be an element on 'lowest common denominator' just in
> this particular context.
> 
> Does that seem OK?

Of course.

Cheers,

Dejan

> Best wishes.
> 
> 
> -- 
> 
> :  David Lee                                I.T. Service          :
> :  Senior Systems Programmer                Computer Centre       :
> :  UNIX Team Leader                         Durham University     :
> :                                           South Road            :
> :  http://www.dur.ac.uk/t.d.lee/            Durham DH1 3LE        :
> :  Phone: +44 191 334 2752                  U.K.                  :
> _______________________________________________________
> Linux-HA-Dev: [email protected]
> http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
> Home Page: http://linux-ha.org/
_______________________________________________________
Linux-HA-Dev: [email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/

Reply via email to