From: "Jiří Paleček" <jpalecek@web.de>
To: Garrett Cooper <yanegomi@gmail.com>
Cc: ltp-list@lists.sourceforge.net
Subject: Re: [LTP] [PATCH] Fix some bashisms
Date: Tue, 07 Jul 2009 12:29:04 +0200 [thread overview]
Message-ID: <op.uwo0qqw7u2flwt@debian> (raw)
In-Reply-To: <364299f40907061731j70ec779asf40630eb9b2e83b4@mail.gmail.com>
On Tue, 07 Jul 2009 02:31:25 +0200, Garrett Cooper <yanegomi@gmail.com>
wrote:
> 2009/7/6 Jiří Paleček <jpalecek@web.de>:
>> On Tue, 07 Jul 2009 01:33:29 +0200, Garrett Cooper <yanegomi@gmail.com>
>> wrote:
>>
>>> On Mon, Jul 6, 2009 at 3:47 PM, Jiri Palecek<jpalecek@web.de> wrote:
>>>>
>>>> On Monday 06 July 2009 19:45:08 Garrett Cooper wrote:
>>>>>
>>>>> 2. All numeric test(1) comparisons could and should be switched from:
>>>>>
>>>>> command
>>>>> if [ $? = 0 ]; then
>>>>>
>>>>> to:
>>>>>
>>>>> if command; then
>>>>>
>>>>> for brevity.
>>>>
>>>> Why should them be changed? This is only a cosmetic change, which
>>>> would
>>>> make the patch unnecessarily larger (when it's already a little too
>>>> large
>>>> IMHO). If it could be in the former form till now, I think it can
>>>> stay there
>>>> a few months/years.
>>>>
>>>> IMHO this usage is still much better than
>>>>
>>>> command; RC=$?
>>>> if [ $RC = 0 ] ...
>>>> ... RC is not read later ...
>>>>
>>>> or (incorrect)
>>>>
>>>> command || RC=$?
>>>> if [ $RC = 0 ] ...
>>>
>>> Yes, I agree with what you said about the above usage, but if you're
>>> not using $? for other than just the [ $? -ne 0 ], then I wouldn't
>>> even bother doing that, because if command; then saves a fork-exec,
>>> and an additional line in the source. As long as it's readable and
>>> doesn't expand multiple lines with a trailing \, you're fine.
>>
>> Are you talking only about efficiency and bash scripts? :-)
>
> Efficiency, and more importantly readability.
>
>> Anyway, if you want to save the fork-exec, you can just use a shell
>> with a
>> test builtin (ksh, bash, dash ... and I believe many others do).
>>
>> If you are concerned about readability, I suggest considering another
>> alternative:
>>
>> command || {
>> do_something_on_error
>> }
>>
>> command && {
>> do_something_when_ok
>> }
>>
>> Of course, usable only when there's no "else" branch.
>
> That's ugly and hard to read with large logic blocks.
I don't think so; I have no problems with a similar syntax in C, moreover,
I consider the braces more distinguishable than keywords.
>> Still, I think the original form is correct and quite straightforward. I
>> would probably not use the extra test myself, but I don't feel like it
>> needs
>> changing. Just looking at the patch, I see places where the check is
>> done
>> really suspiciously:
>>
>>
>> tst_resm TINFO "Test #1: changing mtu size of eth0:1 device."
>>
>> - ip link set eth0:1 mtu 300 &>$LTPTMP/tst_ip.err
>> + ip link set eth0:1 mtu 300 >$LTPTMP/tst_ip.err 2>&1
>> if [ $RC -ne 0 ]
>> then
>> tst_res TFAIL $LTPTMP/tst_ip.err \
>>
>> I think this needs much more attention than "calling [ twice" or "extra
>> line
>> in the script".
>
> Yeah, true. Why not run everything through set -u then?
It would not help, IMO. At least in this particular case, the variable is
properly initialized.
Regards
Jiri Palecek
------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize
details at: http://p.sf.net/sfu/blackberry
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
next prev parent reply other threads:[~2009-07-07 10:55 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <4a413e9b.160bca0a.2226.fffff184SMTPIN_ADDED@mx.google.com>
2009-07-06 17:45 ` [LTP] [PATCH] Fix some bashisms Garrett Cooper
2009-07-06 22:02 ` Mike Frysinger
2009-07-06 22:47 ` Jiri Palecek
2009-07-06 23:33 ` Garrett Cooper
2009-07-07 0:16 ` Jiří Paleček
2009-07-07 0:31 ` Garrett Cooper
2009-07-07 10:29 ` Jiří Paleček [this message]
[not found] <200910211528.n9LFST8q028289@e35.co.us.ibm.com>
2009-10-26 17:02 ` Subrata Modak
2009-10-26 19:37 ` Garrett Cooper
2009-10-29 18:12 ` JiříPaleček
2009-10-30 11:37 ` Subrata Modak
2009-10-30 12:53 ` Jiří Paleček
2009-10-30 12:19 ` Subrata Modak
2009-10-31 6:39 ` Garrett Cooper
2009-10-31 11:42 ` Jiří Paleček
2009-11-01 0:15 ` Garrett Cooper
[not found] <4adf2acd.8b13f30a.0849.7847SMTPIN_ADDED@mx.google.com>
2009-10-21 19:38 ` Mike Frysinger
2009-10-21 0:19 Jiri Palecek
-- strict thread matches above, loose matches on Subject: below --
2009-07-07 8:35 Jiri Palecek
2009-07-07 15:32 ` Subrata Modak
2009-07-07 16:26 ` Garrett Cooper
2009-07-08 19:05 ` Mike Frysinger
2009-07-08 18:13 ` Subrata Modak
[not found] <4a413e95.8d13f30a.1199.ffffdccbSMTPIN_ADDED@mx.google.com>
2009-06-23 21:21 ` Mike Frysinger
2009-06-25 9:09 ` Subrata Modak
2009-06-30 7:41 ` Subrata Modak
2009-07-06 23:12 ` Jiri Palecek
2009-05-31 21:27 Jiri Palecek >
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=op.uwo0qqw7u2flwt@debian \
--to=jpalecek@web.de \
--cc=ltp-list@lists.sourceforge.net \
--cc=yanegomi@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox