sh guide, particularly for numerical operators

I think I have a solution to this, but I'd appreciate links to other documentation or books (paid is fine!) that specifically deal with FreeBSD's sh, because search engines are hopelessly polluted by bash.

What I'm trying to do is check if a FreeBSD version is higher than a specific number via a makefile, which I decided to do in shell (possibly a mistake, awk might be easier). My solution so far is :
Code:
vernum=`uname -r`
vrdigit=${vernum%%.*}
vrdnum=$((vrdigit))
if [  $vrdnum -gt 10  ]; then
..etc
It's not incredibly well documented though, and rather confusing, because > can be used when doing arithmetic operations inside (()) but not inside if, where it needs -gt. -gt appears to be documented here


but it's not in the sh man page. If I do a man 1 if it just takes me to builtin. Not to mention that shell in general and 'if' in particular are incredibly fussy about white space.

Am I missing a particularly obvious guide, or link?
 
(possibly a mistake, awk might be easier)
Yes, definitely. Small scripts can be embedded directly in makefiles, larger ones in separate files. I find awk more readable, maintainable, and scalable than shell scripts. You can easily store multiple data points in a single file to parse them later.

Parsing layout "name value" :
Code:
    @awk '\
        $$1 == "code_total" { \
            printf("\t%-16s : %s\n", "lines of code", $$2); \
        }' ${FILE_CLOCDATA}
 
Back
Top