[SM-Discuss] grimoire function to check minimum kernel ver

Jeremy Blosser (emrys) jblosser-smgl at firinn.org
Tue Apr 4 17:12:16 EDT 2006


On Apr 04, Andrew [afrayedknot at thefrayedknot.armory.com] wrote:
> On Tue, Apr 04, 2006 at 08:18:34PM +0300, Juuso Alasuutari wrote:
> > > > function is_kernel_minimum() {
> > > > ? local MIN CUR a b n=1
> > > > ? MIN=`expr $1 : '\(^[^-]*\)'`
> > > > ? MIN=${MIN//\./\ }
> > > > ? CUR=`get_kernel_version`
> > > > ? CUR=`expr $CUR : '\(^[^-]*\)'`
> > > > ? CUR=${CUR//\./\ }
> > > > ? for a in $MIN; do
> > > > ? ? b=`echo $CUR | cut -d" " -f$n`
> > > > ? ? if (( a < b )); then
> > > > ? ? ? return 0
> > > > ? ? elif (( a > b )); then
> > > > ? ? ? return 1
> > > > ? ? fi
> > > > ? ? (( n += 1 ))
> > > > ? done
> > > > }
> > >
> > > I haven't vetted this entirely, but what first caught my attention was
> > > the VAR=`command` assignments. I may be wrong, but I believe
> > > VAR=$(command) is the preferred method.
> > >
> > > -sandalle
> > 
> > Alright. What difference do `` and $() have all in all?
> > 
> 
> They are functionally equivalent; they both execute the command and
> evaluate to the command's stdout. However it is possible to nest $() but
> not ``.

You can nest them if you escape them:

$ /bin/sh -c 'echo `echo \`echo \\\`echo foo\\\`\``'
foo

Of course that just makes your other point (readability) that much
stronger.  :-)

> I also find $() a bit easier to distinguish in the code than `` (although
> thats more style/opinion). In sorcery I always prefer $() to `` for that
> reason.
> 
> -Andrew
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
Url : http://lists.ibiblio.org/pipermail/sm-discuss/attachments/20060404/eb88aec8/attachment.bin 


More information about the SM-Discuss mailing list