From: Petr Vorel <pvorel@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 1/1] tst_net.sh: Declare prefix variable as empty
Date: Mon, 12 Jul 2021 08:40:38 +0200 [thread overview]
Message-ID: <YOvj5p/5KL2uRNpT@pevik> (raw)
In-Reply-To: <34959e10-45fc-f7ea-9e2d-ebe186a97859@jv-coder.de>
Hi Joerg,
> Hi,
> On 7/12/2021 7:49 AM, Petr Vorel wrote:
> > Thanks for a review!
> > It's a bit strange to add '=' only single variable, maybe I should have rename
> > the variable.
> > Paranoid approach would be to add '=' to any variable which is assigned only on
> > some circumstance or even any variable which is not assigned to any value.
> > But we probably don't want to do it.
> I think good common practice would be to add it to all variables, where it
> matters.
> There are probably only very few places, where a local variable is not
> assigned before being accessed.
> Maybe there is some kind of shell code linter, that can find uninitialized
> variables?
> A good linter could also find variables, that should be local, but are not.
> But I have never looked into shell code linting.
Thanks for your input.
I'm aware only of shellcheck [1], which I'm not a big fan of (false positives,
useless hints). And yes, in this case it warns about 'local' not being POSIX
=> useless :(.
In testcases/lib/tst_net.sh line 411:
local counter host_id host_range is_counter max_host_id min_host_id net_id prefix tmp type
^-- SC3043: In POSIX sh, 'local' is undefined.
> In fs_bind_lib.sh, OPTIND in fs_bind_check probably also requires setting to
> empty, or better 0.
We use tst_test.sh in OPTIND=1 ("The index of the next argument to be processed
by the getopts builtin command")
> But maybe dash's implementation of getopts does not require it. I only had
> to add local OPTIND for busybox sh iirc...
I used to set local OPTIND (in tst_net.sh), which is obviously not working on
dash.
> Yet another case of: Shellcode is unpredictable :)
Yep, I love shell (understand why everything is slowly rewritten into C).
Kind regards,
Petr
> Joerg
[1] https://github.com/koalaman/shellcheck
next prev parent reply other threads:[~2021-07-12 6:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-09 14:01 [LTP] [PATCH 1/1] tst_net.sh: Declare prefix variable as empty Petr Vorel
2021-07-12 2:00 ` Li Wang
2021-07-12 5:49 ` Petr Vorel
2021-07-12 5:57 ` Joerg Vehlow
2021-07-12 6:40 ` Petr Vorel [this message]
2021-07-12 16:12 ` Petr Vorel
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=YOvj5p/5KL2uRNpT@pevik \
--to=pvorel@suse.cz \
--cc=ltp@lists.linux.it \
/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