[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
how much are "historic" issues with test / [ still an issue
From: |
Christoph Anton Mitterer |
Subject: |
how much are "historic" issues with test / [ still an issue |
Date: |
Tue, 25 May 2021 13:47:23 +0200 |
User-agent: |
Evolution 3.38.3-1 |
Hey again.
Via the other thread I've recently stumbled over test/[’s -o and -a
options being deprecated for some reasons, as e.g. described in the
"Rationale" section of:
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html
I wondered how much shells (especially bash, but perhaps also dash if
someone coincidentally knows) are still affected by this?
1) > test "$1" -a "$2"
> should be written as:
> test "$1" && test "$2"
So AFAIU, the problem here is that whenever any user input ($var)
contains a string that might be taken as a operator (i.e. ( ! or
starting with -) ambiguous results could come out.
The example given was $1 set to ! and $2 being empty, in which case, I
guess -a is taken as a string as if ! $var was written.
But the result seems to be the same as with && ... and even if one
takes bash with has the unary -a FILE ... it doesn't seem to do a:
! ( -a FILE )
2) Allegedly on "historical systems" (only?)
> The two commands:
> test "$1"
> test ! "$1"
should be written as:
> test -n "$1"
> test -z "$1"
Even more importantly for me, cases like:
> test "$response" = "expected string"
shall be written as:
> test "X$response" = "Xexpected string"
I guess the leading X is simply to "escape" any possible meta-character
like ( ! or -, right ?
If one doesn't use more than 3 params, i.e. no parentheses -a -o, is
there any chance that a:
"$str1" op "str2"
could be still taken wrongly, if not adding the X?
So are these still an issue with modern versions of bash (and dash,
etc.)?
At least the case of:
> test -d $1 -o -d $2
seems to be "still" an issue if $1 is =
Thanks,
Chris.
- how much are "historic" issues with test / [ still an issue,
Christoph Anton Mitterer <=
- Re: how much are "historic" issues with test / [ still an issue, Greg Wooledge, 2021/05/25
- Re: how much are "historic" issues with test / [ still an issue, Chet Ramey, 2021/05/25
- Re: how much are "historic" issues with test / [ still an issue, Christoph Anton Mitterer, 2021/05/25
- Re: how much are "historic" issues with test / [ still an issue, Greg Wooledge, 2021/05/25
- Re: how much are "historic" issues with test / [ still an issue, Chet Ramey, 2021/05/25
- Re: how much are "historic" issues with test / [ still an issue, Christoph Anton Mitterer, 2021/05/25
- Re: how much are "historic" issues with test / [ still an issue, Greg Wooledge, 2021/05/25
- Re: how much are "historic" issues with test / [ still an issue, Chet Ramey, 2021/05/25