Quote:
You have got me curious as it works for me and I thought I had a proper version of sh.
There is almost no such thing as "proper sh". On some systems, sh gets you ksh. On some systems, sh gets you bash. On Solaris, sh gets you something so old and mouldy it's not even POSIX. If you write a plain sh script it should work in almost anything, but it's all too easy to use non-sh features. Frankly, it's tempting, because some of them are just so convenient.
Like the math you've been using, $(( X + 5 )) sort of syntax. That's a bash/ksh thing and not available in pure POSIX bourne shells.
I'd recommend making this script BASH-only anyway, because some of the sector numbers etc. are going to be extremely high numbers, even beyond the 32-bit limit, and the only shell I know of which can tolerate these for integer math is BASH, and only relatively new BASH at that.
Quote:
The string is treated as an expression and so returns false if empty and true otherwise. I am not sure if there is any benefit of the -z and -n tests over this form, but I have always used this way as I find it more readable as it corresponds with other languages.
The benefit is that, if someone plugs strange values into it, it won't blow up or respond inappropriately. Leaving it open-ended like that means could feed something strange into it and cause
syntax errors.
Always tell [ ] what you want to do with the data inside them.