RE: dhcpcd-hooks/10-mtu modification inquiry
Roy Marples
Wed Jan 27 02:55:07 2016
On 2016-01-26 16:27, Maynard, Chris wrote:
The reason I used [[ ]] and && instead of [] and && is that &&
"short-circuits" the evaluation whereas -a does not, which was the
desired behavior.
I strongly disagree :)
With shell, portability is paramount over optimisation.
Heck, in the expression it's non forking so it's literally which is the
faster shell - by enforcing bash you automatically discard any other.
Once portable. you find that running the same script in bash is slower
than say in dash.
For example
if [[ $(some_cmd) -ge 576 && $(n_other_cmd) -ne "$ifmtu" ]]; then
So, n_other_cmd is not evaluated if some_cmd is less than 576.
if [ $(some_cmd) -ge 576 ] && [ $(n_other_cmd) -ne "$ifmtu" ]; then
This is easily demonstrated thus:
$ rm -f /tmp/a /tmp/b
$ [ $(echo foo >/tmp/a; echo foo) = foo ] && [ $(echo bar >/tmp/b; echo
bar) = bar ] && echo foobar
foobar
$ cat /tmp/a /tmp/b
foo
bar
So both sides are evaluated and proved via files.
Let is make the first test fail
$ rm -f /tmp/a /tmp/b
$ [ $(echo foo >/tmp/a; echo fail) = foo ] && [ $(echo bar >/tmp/b; echo
bar) = bar ] && echo foobar
$ cat /tmp/a /tmp/b
foo
cat: /tmp/b: No such file or directory
This proves that the second test is not evaluated, which satisfies your
initial criteria while remaining portable.
I do look forward to an upgrade, and I'm sure we will at some point,
but package upgrades seem to take a long time to materialize here, so
at the moment I'm stuck with 5.6.7. Actually, we're right on the
cutting edge -- too bad it's the trailing edge. :( To give you an
idea, it wasn't that long ago that we were still using dhcpcd 1.3:
http://www.phystech.com/download/dhcpcd_man.html.
Ewwwww!!!!!
dhcpcd has come a long way since then ....
Roy
Archive administrator: postmaster@marples.name