Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Diplomacy is the art of saying "nice doggy" until you can find a rock.


devel / comp.unix.shell / Re: bash: test: -v: binary operator expected

SubjectAuthor
* bash: test: -v: binary operator expectedhongy...@gmail.com
+- Re: bash: test: -v: binary operator expectedhongy...@gmail.com
`* Re: bash: test: -v: binary operator expectedKeith Thompson
 +* Re: bash: test: -v: binary operator expectedhongy...@gmail.com
 |+* Re: bash: test: -v: binary operator expectedhongy...@gmail.com
 ||`* Re: bash: test: -v: binary operator expectedJanis Papanagnou
 || `* Re: bash: test: -v: binary operator expectedhongy...@gmail.com
 ||  `* Re: bash: test: -v: binary operator expectedKeith Thompson
 ||   `- Re: bash: test: -v: binary operator expectedKenny McCormack
 |`- Re: bash: test: -v: binary operator expectedLew Pitcher
 `* Re: bash: test: -v: binary operator expectedJohn-Paul Stewart
  `* Re: bash: test: -v: binary operator expectedhongy...@gmail.com
   +* Re: bash: test: -v: binary operator expectedDavid W. Hodgins
   |+- Re: bash: test: -v: binary operator expectedhongy...@gmail.com
   |`* Re: bash: test: -v: binary operator expectedKeith Thompson
   | `* Re: bash: test: -v: binary operator expectedhongy...@gmail.com
   |  +- Re: bash: test: -v: binary operator expectedJanis Papanagnou
   |  `* Re: bash: test: -v: binary operator expectedTony Oliver
   |   `- Re: bash: test: -v: binary operator expectedhongy...@gmail.com
   +- Re: bash: test: -v: binary operator expectedKeith Thompson
   `* Re: bash: test: -v: binary operator expectedLew Pitcher
    +* Re: bash: test: -v: binary operator expectedJohn-Paul Stewart
    |`- Re: bash: test: -v: binary operator expectedhongy...@gmail.com
    `* Re: bash: test: -v: binary operator expectedhongy...@gmail.com
     `* Re: bash: test: -v: binary operator expectedChris Elvidge
      `* Re: bash: test: -v: binary operator expectedhongy...@gmail.com
       `* Re: bash: test: -v: binary operator expectedChris Elvidge
        `- Re: bash: test: -v: binary operator expectedhongy...@gmail.com

Pages:12
Re: bash: test: -v: binary operator expected

<ssriie$ca7$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4904&group=comp.unix.shell#4904

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: chr...@mshome.net (Chris Elvidge)
Newsgroups: comp.unix.shell
Subject: Re: bash: test: -v: binary operator expected
Date: Wed, 26 Jan 2022 13:32:46 +0000
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <ssriie$ca7$1@dont-email.me>
References: <fd59c913-a21b-4120-95fb-f90ef611885cn@googlegroups.com>
<87y235oqe5.fsf@nosuchdomain.example.com> <j5810lF492U1@mid.individual.net>
<4c40e948-5704-4888-9762-552a48c52a0an@googlegroups.com>
<ssp5jg$4eu$1@dont-email.me>
<84a5462d-f043-4785-b520-616d01a115acn@googlegroups.com>
<ssrct9$3mb$1@dont-email.me>
<490366be-d3f7-43fd-a636-e84574b27409n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 26 Jan 2022 13:33:02 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="b56770b0bd18cca8c8e04caea639168c";
logging-data="12615"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+cRRroJLsoiEt5SQq6xDJqbfIhiW3ZuE4="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101
Thunderbird/52.2.1 Lightning/5.4
Cancel-Lock: sha1:lSlTt5n93hqqf8B1d25Dg7W9rrI=
In-Reply-To: <490366be-d3f7-43fd-a636-e84574b27409n@googlegroups.com>
Content-Language: en-GB
 by: Chris Elvidge - Wed, 26 Jan 2022 13:32 UTC

On 26/01/2022 12:51, hongy...@gmail.com wrote:
> On Wednesday, January 26, 2022 at 7:56:30 PM UTC+8, Chris Elvidge wrote:
>> I know I'm stupid to ask this,
>
> Absolutely no. Everyone does things according to their own logic, which is not so stupid, at least from their own point of view.
>
>> but why do you insist on 'test'ing a linux/unix command?
>
> Just in order to verify the above-mentioned working mechanism of test.

But you didn't. You verified that you had the command structure wrong.
Try: test $(command -v git)
Or: C=$(command -v git); test -v C
At least then you know which -v is implemented when.

>
>> Surely:
>> command -v git && echo "git installed" || echo "git not installed"
>> would suffice.
>
> Agreed.
>

--
Chris Elvidge
England

Re: bash: test: -v: binary operator expected

<2a919f78-62eb-4636-8dae-f19f4fc74a07n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4931&group=comp.unix.shell#4931

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:620a:29d2:: with SMTP id s18mr1417116qkp.730.1643258735042;
Wed, 26 Jan 2022 20:45:35 -0800 (PST)
X-Received: by 2002:ad4:5dc5:: with SMTP id m5mr1729836qvh.79.1643258734892;
Wed, 26 Jan 2022 20:45:34 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Wed, 26 Jan 2022 20:45:34 -0800 (PST)
In-Reply-To: <ssriie$ca7$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=165.22.62.56; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 165.22.62.56
References: <fd59c913-a21b-4120-95fb-f90ef611885cn@googlegroups.com>
<87y235oqe5.fsf@nosuchdomain.example.com> <j5810lF492U1@mid.individual.net>
<4c40e948-5704-4888-9762-552a48c52a0an@googlegroups.com> <ssp5jg$4eu$1@dont-email.me>
<84a5462d-f043-4785-b520-616d01a115acn@googlegroups.com> <ssrct9$3mb$1@dont-email.me>
<490366be-d3f7-43fd-a636-e84574b27409n@googlegroups.com> <ssriie$ca7$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <2a919f78-62eb-4636-8dae-f19f4fc74a07n@googlegroups.com>
Subject: Re: bash: test: -v: binary operator expected
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Thu, 27 Jan 2022 04:45:35 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 8
 by: hongy...@gmail.com - Thu, 27 Jan 2022 04:45 UTC

On Wednesday, January 26, 2022 at 9:33:07 PM UTC+8, Chris Elvidge wrote:
> On 26/01/2022 12:51, hongy...@gmail.com wrote:
> > Just in order to verify the above-mentioned working mechanism of test.
> But you didn't. You verified that you had the command structure wrong.
> Try: test $(command -v git)
> Or: C=$(command -v git); test -v C
> At least then you know which -v is implemented when.

Thank you for providing me with clearer verification examples.

Re: bash: test: -v: binary operator expected

<ssuafj$tm0$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4932&group=comp.unix.shell#4932

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.unix.shell
Subject: Re: bash: test: -v: binary operator expected
Date: Thu, 27 Jan 2022 14:33:23 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 93
Message-ID: <ssuafj$tm0$1@dont-email.me>
References: <fd59c913-a21b-4120-95fb-f90ef611885cn@googlegroups.com>
<87y235oqe5.fsf@nosuchdomain.example.com>
<c4305d28-bb81-47c9-828a-e16986f5b1a1n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 27 Jan 2022 14:33:23 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="6780cb87180ecc027d43d6588ce101ba";
logging-data="30400"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+0EDb6owchhxC8+gauMKNF59l5x6TlqN4="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:iFwsJKFLVOILml3RH/fQqpEhYAM=
 by: Lew Pitcher - Thu, 27 Jan 2022 14:33 UTC

On Sun, 23 Jan 2022 18:15:12 -0800, hongy...@gmail.com wrote:

> On Monday, January 24, 2022 at 9:48:24 AM UTC+8, Keith Thompson wrote:
>> "hongy...@gmail.com" <hongy...@gmail.com> writes:
>> > See the following error:
>> >
>> > $ test ! command -v git bash: test: -v: binary operator expected
>> As expected, since `test` has no `-v` operator.
>> > But both the following two methods work:
>> >
>> > $ test ! 'command -v git'; echo $?
>> > 1
>> > $ test ! "command -v git"; echo $?
>> > 1
>> As expected. Both could be simplified to `echo 1`.
>>
>> They "work" in the sense that they do not print an error message. Both
>> test whether the specified quoted string is empty. You could replace
>> "command" and "git" by "foo" and "bar" respectively, with the same
>> results.
>
> Thank you for pointing this out:
>
> $ test ! "foo -v bar"; echo $?
> 1
> $ test ! 'foo -v bar'; echo $?
> 1
>
>
>> > Any hints for this behavior?
>> Yes. State what you're trying to do, then figure out what command you
>> need to use to do that.
>
> I want to check if the `git` command exists on the system. And also
> noticed the following usage here [1]:
>
> $ if test ! `command -v git` ; then echo "git not found. Please make
> sure git is installed."; fi
>
> But it seems that the command substitution, i.e., "``" or "$()" shell
> structure is not designed to just only obtain the exit code. So, I think
> the above usage is at least not idiomatic and would like to improve it.

No, you are just using the wrong tools.

Try

if ! command -v git >/dev/null
then
echo git not found
fi

or
! command -v git >/dev/null && echo git not found

or, better yet,
command -v git >/dev/null || echo git not found

You see, the bash <<if>> construct evaluates exit codes, as do
both the bash <<&&>> and <<||>> constructs. But, neither the
bash <<test>> construct nor test(1) evaluate exit codes as part
of their expression, and to get them to evaluate exit codes, you
have to go through the contortions of first capturing the exit
code as a string, and then having <<test>> or test(1) check the
contents of that string.

If you insist on using the bash <<test>> builtin or test(1), then
you /don't/ need to check the exit code from <<command>>. As
<<command>> (with the -v option) will output the path to the command
(on success) or nothing (on failure), both of which the shell handles
as strings, <<test>> or test(1) can check the results from <<command>>
without resorting to checking it's exit code.

And, that's where
if test ! `command -v git`
then
echo "git not found. Please make sure git is installed."
fi
comes from.

> [1] https://gitlab.com/QEF/q-e/-/merge_requests/1725#note_818943793
>
>> Also study the documentation for the `test`
>> command. And next time, please do all this before posting.

--
Lew Pitcher
"In Skills, We Trust"

Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor