Brian J. Murrell
2009-Dec-06 05:27 UTC
printf "%2d%02d%02d\n" 2 6 30 == invalid number with busybox /bin/sh
On my OpenWRT shorewall6-lite (4.2.8) machine, observe the following: # /bin/sh -c ''printf "%2d%02d%02d\n" 2 6 30 9'' 20630 9sh: : invalid number 00sh: : invalid number 00 # /bin/sh -c ''printf "%2d%02d%02d%02d\n" 2 6 30 9'' 2063009 So it looks like printf doesn''t like having more digits than format in the busybox bourne shell. I could hack up either of the two solutions available, one being the above or the other being stripping the kernel version down to 3 positions. I''m just not sure which you want long-term. Cheers, b. ------------------------------------------------------------------------------ Join us December 9, 2009 for the Red Hat Virtual Experience, a free event focused on virtualization and cloud computing. Attend in-depth sessions from your desk. Your couch. Anywhere. http://p.sf.net/sfu/redhat-sfdev2dev
Tom Eastep
2009-Dec-06 06:12 UTC
Re: printf "%2d%02d%02d\n" 2 6 30 == invalid number with busybox /bin/sh
Brian J. Murrell wrote:> On my OpenWRT shorewall6-lite (4.2.8) machine, observe the following: > > # /bin/sh -c ''printf "%2d%02d%02d\n" 2 6 30 9'' > 20630 > 9sh: : invalid number > 00sh: : invalid number > 00 > # /bin/sh -c ''printf "%2d%02d%02d%02d\n" 2 6 30 9'' > 2063009 > > So it looks like printf doesn''t like having more digits than format in > the busybox bourne shell. > > I could hack up either of the two solutions available, one being the > above or the other being stripping the kernel version down to 3 > positions. I''m just not sure which you want long-term.What does ''uname -r'' return on this box? -Tom -- Tom Eastep \ When I die, I want to go like my Grandfather who Shoreline, \ died peacefully in his sleep. Not screaming like Washington, USA \ all of the passengers in his car http://shorewall.net \________________________________________________ ------------------------------------------------------------------------------ Join us December 9, 2009 for the Red Hat Virtual Experience, a free event focused on virtualization and cloud computing. Attend in-depth sessions from your desk. Your couch. Anywhere. http://p.sf.net/sfu/redhat-sfdev2dev
Brian J. Murrell
2009-Dec-06 13:41 UTC
Re: printf "%2d%02d%02d\n" 2 6 30 == invalid number with busybox /bin/sh
On Sat, 2009-12-05 at 22:12 -0800, Tom Eastep wrote:> > What does ''uname -r'' return on this box?As you probably suspect (but I don''t blame ya for asking: # uname -r 2.6.30.9 Cheers, b. ------------------------------------------------------------------------------ Join us December 9, 2009 for the Red Hat Virtual Experience, a free event focused on virtualization and cloud computing. Attend in-depth sessions from your desk. Your couch. Anywhere. http://p.sf.net/sfu/redhat-sfdev2dev
Tom Eastep
2009-Dec-06 15:52 UTC
Re: printf "%2d%02d%02d\n" 2 6 30 == invalid number with busybox /bin/sh
Brian J. Murrell wrote:> On Sat, 2009-12-05 at 22:12 -0800, Tom Eastep wrote: >> What does ''uname -r'' return on this box? > > As you probably suspect (but I don''t blame ya for asking: > > # uname -r > 2.6.30.9Well, since kernel versions ARE of the form xx.yy.zz, I guess the proper workaround is to strip this non-standard 4-part form down to 3. -Tom -- Tom Eastep \ When I die, I want to go like my Grandfather who Shoreline, \ died peacefully in his sleep. Not screaming like Washington, USA \ all of the passengers in his car http://shorewall.net \________________________________________________ ------------------------------------------------------------------------------ Join us December 9, 2009 for the Red Hat Virtual Experience, a free event focused on virtualization and cloud computing. Attend in-depth sessions from your desk. Your couch. Anywhere. http://p.sf.net/sfu/redhat-sfdev2dev
Brian J. Murrell
2009-Dec-06 18:20 UTC
Re: printf "%2d%02d%02d\n" 2 6 30 == invalid number with busybox /bin/sh
On Sun, 2009-12-06 at 07:52 -0800, Tom Eastep wrote:> Well, since kernel versions ARE of the form xx.yy.zz, I guess the proper > workaround is to strip this non-standard 4-part form down to 3.This seems to work: # kernel=$(printf "%2d%02d%02d\n" $(uname -r 2> /dev/null | sed -e ''s/-.*//'' -e ''s/^\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/\1 \2 \3/g'')) # echo $kernel 20630 It drops a redundant echo as well as the need for the tr (which was redundant in the first place given the existing use of sed) to convert dots to spaces and the head -n1, which, TBH, I''m unclear as to why it would ever have been needed. Cheers, b. ------------------------------------------------------------------------------ Join us December 9, 2009 for the Red Hat Virtual Experience, a free event focused on virtualization and cloud computing. Attend in-depth sessions from your desk. Your couch. Anywhere. http://p.sf.net/sfu/redhat-sfdev2dev
Tom Eastep
2009-Dec-06 22:26 UTC
Re: printf "%2d%02d%02d\n" 2 6 30 == invalid number with busybox /bin/sh
Brian J. Murrell wrote:> On Sun, 2009-12-06 at 07:52 -0800, Tom Eastep wrote: >> Well, since kernel versions ARE of the form xx.yy.zz, I guess the proper >> workaround is to strip this non-standard 4-part form down to 3. > > This seems to work: > > # kernel=$(printf "%2d%02d%02d\n" $(uname -r 2> /dev/null | sed -e ''s/-.*//'' -e ''s/^\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/\1 \2 \3/g'')) > # echo $kernel > 20630 > > It drops a redundant echo as well as the need for the tr (which was > redundant in the first place given the existing use of sed) to convert > dots to spaces and the head -n1, which, TBH, I''m unclear as to why it > would ever have been needed.Thanks, -Tom -- Tom Eastep \ When I die, I want to go like my Grandfather who Shoreline, \ died peacefully in his sleep. Not screaming like Washington, USA \ all of the passengers in his car http://shorewall.net \________________________________________________ ------------------------------------------------------------------------------ Join us December 9, 2009 for the Red Hat Virtual Experience, a free event focused on virtualization and cloud computing. Attend in-depth sessions from your desk. Your couch. Anywhere. http://p.sf.net/sfu/redhat-sfdev2dev