mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 1/3] commands/test: Bail out on incomplete command line options
Date: Mon, 3 Feb 2020 09:50:17 +0100	[thread overview]
Message-ID: <20200203085017.qjy422frw27w6ppm@pengutronix.de> (raw)
In-Reply-To: <20200203075707.wc2q5f4isveehjuk@pengutronix.de>

On Mon, Feb 03, 2020 at 08:57:07AM +0100, Sascha Hauer wrote:
> On Tue, Jan 28, 2020 at 02:07:59PM +0100, Uwe Kleine-König wrote:
> > This makes test emit an error (and fail) on e.g.
> > 
> > 	test -f
> 
> test -f in bash returns 0 as well and also doesn't emit an error.

Ah, that's because this is implicitly

	test -n -f

That the same happens in barebox is only an accident I would say. (And
note that currently

	test ''

returns success, too, which is different from bash's test behaviour.)

> > and also on unimplemented options like
> > 
> > 	test -c /dev/null
> 
> test -H /foo/bar in bash says "bash: test: -H: unary operator expected".

That is (again) because "-H" "/dev/null" is implicitly "-n" "-H"
"/dev/null" and then there is no sane interpretation of the last
argument.

	test -H -a -f

succeeds because both "-H" and "-f" are non-zero. I'm not sure if trying
to be that clever(?) is a good idea. (Also bash's test isn't without
shortages, for example

	$ test -f -a -a -f
	bash: test: argument expected

while this is an obviously fine test if a file called "-a" exists and
"-f" is not zero-length. Also note that coreutil's test behaves differently
than bash's on for example

	test -f -a -f
	
. (bash returns success, coreutil's test wails about "extra argument
‘-f’".))

> I am not sure how relevant this is, but the behaviour you introduce is
> not consistent to bash.

While I admit I wasn't aware how strange the other test variants are, I
think trying to be as smart as bash's and coreutil's test isn't very
sensible. So I think requesting that the caller explicitly uses "-n" for
testing an argument for being non-empty is a sane idea. Not only because
it catches (probably) errors like:

	somestring=""
	if test -n $somestring; then echo some string is nonempty; fi

but also to keep the parser simpler (and the result less surprising).

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2020-02-03  8:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-28 13:07 [PATCH 0/3] commands/test: some improvements Uwe Kleine-König
2020-01-28 13:07 ` [PATCH 1/3] commands/test: Bail out on incomplete command line options Uwe Kleine-König
2020-02-03  7:57   ` Sascha Hauer
2020-02-03  8:50     ` Uwe Kleine-König [this message]
2020-01-28 13:08 ` [PATCH 2/3] commands/test: Improve option parsing to handle "]" less special Uwe Kleine-König
2020-01-28 13:08 ` [PATCH 3/3] commands/test: Implement -b and -c to test for character and block devices Uwe Kleine-König
2020-02-04  7:40 ` [PATCH 0/3] commands/test: some improvements Sascha Hauer

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=20200203085017.qjy422frw27w6ppm@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    /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