Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

<lilo> I've always wanted to have a web site with a big picture of a carrot on it


devel / comp.unix.shell / 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
bash: test: -v: binary operator expected

<fd59c913-a21b-4120-95fb-f90ef611885cn@googlegroups.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:622a:589:: with SMTP id c9mr5466287qtb.58.1642987687759;
Sun, 23 Jan 2022 17:28:07 -0800 (PST)
X-Received: by 2002:a37:94c1:: with SMTP id w184mr9862084qkd.264.1642987687605;
Sun, 23 Jan 2022 17:28:07 -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: Sun, 23 Jan 2022 17:28:07 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=139.59.109.137; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 139.59.109.137
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <fd59c913-a21b-4120-95fb-f90ef611885cn@googlegroups.com>
Subject: bash: test: -v: binary operator expected
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Mon, 24 Jan 2022 01:28:07 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 15
 by: hongy...@gmail.com - Mon, 24 Jan 2022 01:28 UTC

See the following error:

$ test ! command -v git
bash: test: -v: binary operator expected

But both the following two methods work:

$ test ! 'command -v git'; echo $?
1 $ test ! "command -v git"; echo $?
1

Any hints for this behavior?

Regards,
HZ

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

<68da012b-42ab-451d-9161-8cb0914ed730n@googlegroups.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:ac8:7f88:: with SMTP id z8mr11195529qtj.396.1642988133773;
Sun, 23 Jan 2022 17:35:33 -0800 (PST)
X-Received: by 2002:a05:6214:20aa:: with SMTP id 10mr13128038qvd.40.1642988133666;
Sun, 23 Jan 2022 17:35:33 -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: Sun, 23 Jan 2022 17:35:33 -0800 (PST)
In-Reply-To: <fd59c913-a21b-4120-95fb-f90ef611885cn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=139.59.109.137; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 139.59.109.137
References: <fd59c913-a21b-4120-95fb-f90ef611885cn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <68da012b-42ab-451d-9161-8cb0914ed730n@googlegroups.com>
Subject: Re: bash: test: -v: binary operator expected
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Mon, 24 Jan 2022 01:35:33 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 20
 by: hongy...@gmail.com - Mon, 24 Jan 2022 01:35 UTC

On Monday, January 24, 2022 at 9:28:10 AM UTC+8, hongy...@gmail.com wrote:
> See the following error:
>
> $ test ! command -v git
> bash: test: -v: binary operator expected
>
> But both the following two methods work:
>
> $ test ! 'command -v git'; echo $?
> 1
> $ test ! "command -v git"; echo $?
> 1

And another working form:

$ ! (command -v git >/dev/null 2>&1); echo $?
1

So, which one should I use?

HZ

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

<87y235oqe5.fsf@nosuchdomain.example.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.unix.shell
Subject: Re: bash: test: -v: binary operator expected
Date: Sun, 23 Jan 2022 17:48:18 -0800
Organization: None to speak of
Lines: 32
Message-ID: <87y235oqe5.fsf@nosuchdomain.example.com>
References: <fd59c913-a21b-4120-95fb-f90ef611885cn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="94b3a3008f708f7b40cdf3a125e51cf3";
logging-data="10254"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18NeXqa3ZQR4gf5zAfsmIxJ"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:e9GkWK6inm4BNPFlho7HltDyBmI=
sha1:liRaClZ4xmVMn+5PbNTM2grPB3U=
 by: Keith Thompson - Mon, 24 Jan 2022 01:48 UTC

"hongy...@gmail.com" <hongyi.zhao@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.

> 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. Also study the documentation for the `test`
command. And next time, please do all this before posting.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

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

<c4305d28-bb81-47c9-828a-e16986f5b1a1n@googlegroups.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:620a:1a19:: with SMTP id bk25mr9599275qkb.513.1642990513290;
Sun, 23 Jan 2022 18:15:13 -0800 (PST)
X-Received: by 2002:ad4:5f86:: with SMTP id jp6mr12847474qvb.83.1642990513162;
Sun, 23 Jan 2022 18:15:13 -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: Sun, 23 Jan 2022 18:15:12 -0800 (PST)
In-Reply-To: <87y235oqe5.fsf@nosuchdomain.example.com>
Injection-Info: google-groups.googlegroups.com; posting-host=139.59.109.137; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 139.59.109.137
References: <fd59c913-a21b-4120-95fb-f90ef611885cn@googlegroups.com> <87y235oqe5.fsf@nosuchdomain.example.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <c4305d28-bb81-47c9-828a-e16986f5b1a1n@googlegroups.com>
Subject: Re: bash: test: -v: binary operator expected
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Mon, 24 Jan 2022 02:15:13 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 42
 by: hongy...@gmail.com - Mon, 24 Jan 2022 02:15 UTC

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.

[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.

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

<82380b2e-47a8-455f-b833-acfb3a79a8bdn@googlegroups.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:6214:5192:: with SMTP id kl18mr11787313qvb.50.1642991707971;
Sun, 23 Jan 2022 18:35:07 -0800 (PST)
X-Received: by 2002:a05:6214:ca7:: with SMTP id s7mr12753132qvs.16.1642991707744;
Sun, 23 Jan 2022 18:35:07 -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: Sun, 23 Jan 2022 18:35:07 -0800 (PST)
In-Reply-To: <c4305d28-bb81-47c9-828a-e16986f5b1a1n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=139.59.109.137; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 139.59.109.137
References: <fd59c913-a21b-4120-95fb-f90ef611885cn@googlegroups.com>
<87y235oqe5.fsf@nosuchdomain.example.com> <c4305d28-bb81-47c9-828a-e16986f5b1a1n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <82380b2e-47a8-455f-b833-acfb3a79a8bdn@googlegroups.com>
Subject: Re: bash: test: -v: binary operator expected
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Mon, 24 Jan 2022 02:35:07 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 43
 by: hongy...@gmail.com - Mon, 24 Jan 2022 02:35 UTC

On Monday, January 24, 2022 at 10:15:15 AM UTC+8, 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.

To summarize, which of the following method is preferred?

$ test ! `command -v git` ; echo $?
1

$ ! (command -v git >/dev/null 2>&1); echo $?
1

HZ

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

<sslip0$vgs$1@dont-email.me>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: bash: test: -v: binary operator expected
Date: Mon, 24 Jan 2022 07:59:44 +0100
Organization: A noiseless patient Spider
Lines: 79
Message-ID: <sslip0$vgs$1@dont-email.me>
References: <fd59c913-a21b-4120-95fb-f90ef611885cn@googlegroups.com>
<87y235oqe5.fsf@nosuchdomain.example.com>
<c4305d28-bb81-47c9-828a-e16986f5b1a1n@googlegroups.com>
<82380b2e-47a8-455f-b833-acfb3a79a8bdn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 24 Jan 2022 06:59:44 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="e945d30b69a00fa78fa2ae3b9221be5e";
logging-data="32284"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18o8SsWbLxDbhIr1X6xDSYI"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:t9HMQpMnpc32nweSJOsGshBrhIA=
In-Reply-To: <82380b2e-47a8-455f-b833-acfb3a79a8bdn@googlegroups.com>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Mon, 24 Jan 2022 06:59 UTC

On 24.01.2022 03:35, hongy...@gmail.com wrote:
> On Monday, January 24, 2022 at 10:15:15 AM UTC+8, 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.
>
> To summarize, which of the following method is preferred?

None.

If I want to simply check for existence of a command I'd use
'whence', or 'type', or if you want 'command' then I'd write

command -v git ; echo $?

or in contexts of tests either of

command -v git || echo git non-existing

if command -v git 2>/dev/null
then echo git existing
else echo git non-existing
fi

if ! command -v git
then echo git non-existing
fi

Redirect errors as desired (one sample provided above).

>
> $ test ! `command -v git` ; echo $?
> 1
>
> $ ! (command -v git >/dev/null 2>&1); echo $?
> 1

I would avoid unnecessary stuff like subshell-expansion, and
subshells, and old `...` syntax, and test. Why do you use that
in the first place? (Just a rhetorical question. See Keith's
suggestion for a procedure to develop appropriate shell code;
the core is: "figure out what command you _need_ to use".)

Janis

>
> HZ
>

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

<420743df-2791-4d23-9dc0-1bd6dc4ad0e2n@googlegroups.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:6214:1c8b:: with SMTP id ib11mr15038454qvb.82.1643036130263;
Mon, 24 Jan 2022 06:55:30 -0800 (PST)
X-Received: by 2002:ac8:7f12:: with SMTP id f18mr12419143qtk.643.1643036130107;
Mon, 24 Jan 2022 06:55:30 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!1.us.feeder.erje.net!feeder.erje.net!border1.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: Mon, 24 Jan 2022 06:55:29 -0800 (PST)
In-Reply-To: <sslip0$vgs$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=139.59.109.137; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 139.59.109.137
References: <fd59c913-a21b-4120-95fb-f90ef611885cn@googlegroups.com>
<87y235oqe5.fsf@nosuchdomain.example.com> <c4305d28-bb81-47c9-828a-e16986f5b1a1n@googlegroups.com>
<82380b2e-47a8-455f-b833-acfb3a79a8bdn@googlegroups.com> <sslip0$vgs$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <420743df-2791-4d23-9dc0-1bd6dc4ad0e2n@googlegroups.com>
Subject: Re: bash: test: -v: binary operator expected
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Mon, 24 Jan 2022 14:55:30 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 41
 by: hongy...@gmail.com - Mon, 24 Jan 2022 14:55 UTC

On Monday, January 24, 2022 at 2:59:49 PM UTC+8, Janis Papanagnou wrote:
> If I want to simply check for existence of a command I'd use
> 'whence',

$ whence
whence: command not found

> or 'type', or if you want 'command' then I'd write
> command -v git ; echo $?
> or in contexts of tests either of
>
> command -v git || echo git non-existing
>
> if command -v git 2>/dev/null
> then echo git existing
> else echo git non-existing
> fi
>
> if ! command -v git
> then echo git non-existing
> fi

Yep. This one is what I want.
> Redirect errors as desired (one sample provided above).
> >
> > $ test ! `command -v git` ; echo $?
> > 1
> >
> > $ ! (command -v git >/dev/null 2>&1); echo $?
> > 1
> I would avoid unnecessary stuff like subshell-expansion, and
> subshells, and old `...` syntax, and test.

Thank you again for your good advice.

> Why do you use that in the first place? (Just a rhetorical question. See Keith's
> suggestion for a procedure to develop appropriate shell code;
> the core is: "figure out what command you _need_ to use".)

HZ

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

<j5810lF492U1@mid.individual.net>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: jpstew...@personalprojects.net (John-Paul Stewart)
Newsgroups: comp.unix.shell
Subject: Re: bash: test: -v: binary operator expected
Date: Mon, 24 Jan 2022 11:04:36 -0500
Lines: 16
Message-ID: <j5810lF492U1@mid.individual.net>
References: <fd59c913-a21b-4120-95fb-f90ef611885cn@googlegroups.com>
<87y235oqe5.fsf@nosuchdomain.example.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-Trace: individual.net ZiwimRCB648vNCPJWgvnMAPurpe8xKZPZmDRbyEOeFh4OPWhRS
Cancel-Lock: sha1:mrAW/wbiospocAAoGPF2WIE2ry4=
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Content-Language: en-CA
In-Reply-To: <87y235oqe5.fsf@nosuchdomain.example.com>
 by: John-Paul Stewart - Mon, 24 Jan 2022 16:04 UTC

On 2022-01-23 20:48, Keith Thompson wrote:
> "hongy...@gmail.com" <hongyi.zhao@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.

That depends on which 'test' you're using. The bash built-in 'test'
(which the OP appears to be using) does have a (unary) -v operator.
From 'help test' in bash:

-v VAR True if the shell variable VAR is set.

For which the OP's syntax is (also) obviously wrong.

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

<87zgnkn83q.fsf@nosuchdomain.example.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.unix.shell
Subject: Re: bash: test: -v: binary operator expected
Date: Mon, 24 Jan 2022 13:20:57 -0800
Organization: None to speak of
Lines: 16
Message-ID: <87zgnkn83q.fsf@nosuchdomain.example.com>
References: <fd59c913-a21b-4120-95fb-f90ef611885cn@googlegroups.com>
<87y235oqe5.fsf@nosuchdomain.example.com>
<c4305d28-bb81-47c9-828a-e16986f5b1a1n@googlegroups.com>
<82380b2e-47a8-455f-b833-acfb3a79a8bdn@googlegroups.com>
<sslip0$vgs$1@dont-email.me>
<420743df-2791-4d23-9dc0-1bd6dc4ad0e2n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="94b3a3008f708f7b40cdf3a125e51cf3";
logging-data="19835"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18vHacbOO45N3rVtSLNToKJ"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:qJf28kln1mtdOUIx7x9ctkUq/ms=
sha1:pu86yONPvYh4lBT+nMWBe8A5fno=
 by: Keith Thompson - Mon, 24 Jan 2022 21:20 UTC

"hongy...@gmail.com" <hongyi.zhao@gmail.com> writes:
> On Monday, January 24, 2022 at 2:59:49 PM UTC+8, Janis Papanagnou wrote:
>> If I want to simply check for existence of a command I'd use
>> 'whence',
>
> $ whence
> whence: command not found

"whence" is a builtin command in zsh.

[...]

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

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

<ssnigr$3jfdt$1@news.xmission.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Re: bash: test: -v: binary operator expected
Date: Tue, 25 Jan 2022 01:07:39 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <ssnigr$3jfdt$1@news.xmission.com>
References: <fd59c913-a21b-4120-95fb-f90ef611885cn@googlegroups.com> <sslip0$vgs$1@dont-email.me> <420743df-2791-4d23-9dc0-1bd6dc4ad0e2n@googlegroups.com> <87zgnkn83q.fsf@nosuchdomain.example.com>
Injection-Date: Tue, 25 Jan 2022 01:07:39 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="3784125"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Tue, 25 Jan 2022 01:07 UTC

In article <87zgnkn83q.fsf@nosuchdomain.example.com>,
Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
>"hongy...@gmail.com" <hongyi.zhao@gmail.com> writes:
>> On Monday, January 24, 2022 at 2:59:49 PM UTC+8, Janis Papanagnou wrote:
>>> If I want to simply check for existence of a command I'd use
>>> 'whence',
>>
>> $ whence
>> whence: command not found
>
>"whence" is a builtin command in zsh.

It is also ksh, which is, I think, where Janis is coming from.

--
"I think I understand delicate, but why do I have to wash my hands, and
be standing in cold water when doing it?"

Kaz Kylheku <kaz@kylheku.com> in comp.lang.c

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

<4c40e948-5704-4888-9762-552a48c52a0an@googlegroups.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:622a:d0:: with SMTP id p16mr3557719qtw.386.1643073996927;
Mon, 24 Jan 2022 17:26:36 -0800 (PST)
X-Received: by 2002:a05:6214:20aa:: with SMTP id 10mr17714551qvd.40.1643073996797;
Mon, 24 Jan 2022 17:26:36 -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: Mon, 24 Jan 2022 17:26:36 -0800 (PST)
In-Reply-To: <j5810lF492U1@mid.individual.net>
Injection-Info: google-groups.googlegroups.com; posting-host=139.59.109.137; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 139.59.109.137
References: <fd59c913-a21b-4120-95fb-f90ef611885cn@googlegroups.com>
<87y235oqe5.fsf@nosuchdomain.example.com> <j5810lF492U1@mid.individual.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <4c40e948-5704-4888-9762-552a48c52a0an@googlegroups.com>
Subject: Re: bash: test: -v: binary operator expected
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Tue, 25 Jan 2022 01:26:36 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 24
 by: hongy...@gmail.com - Tue, 25 Jan 2022 01:26 UTC

On Tuesday, January 25, 2022 at 12:04:43 AM UTC+8, John-Paul Stewart wrote:
> On 2022-01-23 20:48, 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.
> That depends on which 'test' you're using. The bash built-in 'test'
> (which the OP appears to be using) does have a (unary) -v operator.
> From 'help test' in bash:
>
> -v VAR True if the shell variable VAR is set.
>
> For which the OP's syntax is (also) obviously wrong.

I'm not using the -v operator 'test' command, instead, here is the -v parameter of 'command':

$ help command
-v print a description of COMMAND similar to the `type' builtin

So, I really don't understand why you give the comments above.

HZ

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

<op.1gi4vspca3w0dxdave@hodgins.homeip.net>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: dwhodg...@nomail.afraid.org (David W. Hodgins)
Newsgroups: comp.unix.shell
Subject: Re: bash: test: -v: binary operator expected
Date: Mon, 24 Jan 2022 21:22:30 -0500
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <op.1gi4vspca3w0dxdave@hodgins.homeip.net>
References: <fd59c913-a21b-4120-95fb-f90ef611885cn@googlegroups.com>
<87y235oqe5.fsf@nosuchdomain.example.com> <j5810lF492U1@mid.individual.net>
<4c40e948-5704-4888-9762-552a48c52a0an@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="f506de1fb287c081960902762d1a2b5e";
logging-data="24356"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ktAIjJssRLE3VFmOz2ze9lcTqEY7Tm9E="
User-Agent: Opera Mail/12.16 (Linux)
Cancel-Lock: sha1:VIPocetwEjhxKGws2UUMmrGR80c=
 by: David W. Hodgins - Tue, 25 Jan 2022 02:22 UTC

On Mon, 24 Jan 2022 20:26:36 -0500, hongy...@gmail.com <hongyi.zhao@gmail.com> wrote:

> On Tuesday, January 25, 2022 at 12:04:43 AM UTC+8, John-Paul Stewart wrote:
>> On 2022-01-23 20:48, 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.
>> That depends on which 'test' you're using. The bash built-in 'test'
>> (which the OP appears to be using) does have a (unary) -v operator.
>> From 'help test' in bash:
>>
>> -v VAR True if the shell variable VAR is set.
>>
>> For which the OP's syntax is (also) obviously wrong.
>
> I'm not using the -v operator 'test' command, instead, here is the -v parameter of 'command':
>
> $ help command
> -v print a description of COMMAND similar to the `type' builtin
>
> So, I really don't understand why you give the comments above.

In order to avoid having the -v option be interpreted as an option passed to the
test command, the "command -v git" must be passed as a single string to the test
command. That's done by enclosing command -v git in quotes.
test ! "command -v git"

Regards, Dave Hodgins

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

<b121be05-6b26-45b9-8db1-26ecf17d1c56n@googlegroups.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:6214:2349:: with SMTP id hu9mr17498684qvb.93.1643079927729;
Mon, 24 Jan 2022 19:05:27 -0800 (PST)
X-Received: by 2002:a37:67d1:: with SMTP id b200mr4946599qkc.785.1643079927533;
Mon, 24 Jan 2022 19:05:27 -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: Mon, 24 Jan 2022 19:05:27 -0800 (PST)
In-Reply-To: <op.1gi4vspca3w0dxdave@hodgins.homeip.net>
Injection-Info: google-groups.googlegroups.com; posting-host=139.59.109.137; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 139.59.109.137
References: <fd59c913-a21b-4120-95fb-f90ef611885cn@googlegroups.com>
<87y235oqe5.fsf@nosuchdomain.example.com> <j5810lF492U1@mid.individual.net>
<4c40e948-5704-4888-9762-552a48c52a0an@googlegroups.com> <op.1gi4vspca3w0dxdave@hodgins.homeip.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b121be05-6b26-45b9-8db1-26ecf17d1c56n@googlegroups.com>
Subject: Re: bash: test: -v: binary operator expected
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Tue, 25 Jan 2022 03:05:27 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 38
 by: hongy...@gmail.com - Tue, 25 Jan 2022 03:05 UTC

On Tuesday, January 25, 2022 at 10:22:43 AM UTC+8, David W. Hodgins wrote:
> On Mon, 24 Jan 2022 20:26:36 -0500, hongy...@gmail.com <hongy...@gmail.com> wrote:
>
> > On Tuesday, January 25, 2022 at 12:04:43 AM UTC+8, John-Paul Stewart wrote:
> >> On 2022-01-23 20:48, 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.
> >> That depends on which 'test' you're using. The bash built-in 'test'
> >> (which the OP appears to be using) does have a (unary) -v operator.
> >> From 'help test' in bash:
> >>
> >> -v VAR True if the shell variable VAR is set.
> >>
> >> For which the OP's syntax is (also) obviously wrong.
> >
> > I'm not using the -v operator 'test' command, instead, here is the -v parameter of 'command':
> >
> > $ help command
> > -v print a description of COMMAND similar to the `type' builtin
> >
> > So, I really don't understand why you give the comments above.
> In order to avoid having the -v option be interpreted as an option passed to the
> test command, the "command -v git" must be passed as a single string to the test
> command. That's done by enclosing command -v git in quotes.
> test ! "command -v git"

I've already posted both of the following forms:

$ test ! "command -v git"
$ test ! 'command -v git'

But when I posted the above usage, I thought it was a little strange.

HZ

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

<87ilu8mlxl.fsf@nosuchdomain.example.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.unix.shell
Subject: Re: bash: test: -v: binary operator expected
Date: Mon, 24 Jan 2022 21:19:50 -0800
Organization: None to speak of
Lines: 40
Message-ID: <87ilu8mlxl.fsf@nosuchdomain.example.com>
References: <fd59c913-a21b-4120-95fb-f90ef611885cn@googlegroups.com>
<87y235oqe5.fsf@nosuchdomain.example.com>
<j5810lF492U1@mid.individual.net>
<4c40e948-5704-4888-9762-552a48c52a0an@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="fbd031f938b902ca86c8b061f35a7f8c";
logging-data="5351"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/xlWh4gAUyEtWZ/Ft7C8p7"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:xi377MpXR9CvLGNwcquwtwihEtc=
sha1:9V2m+bsvk+p2fPMGhwhmlDZaRNc=
 by: Keith Thompson - Tue, 25 Jan 2022 05:19 UTC

"hongy...@gmail.com" <hongyi.zhao@gmail.com> writes:
> On Tuesday, January 25, 2022 at 12:04:43 AM UTC+8, John-Paul Stewart wrote:
>> On 2022-01-23 20:48, 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.
>> That depends on which 'test' you're using. The bash built-in 'test'
>> (which the OP appears to be using) does have a (unary) -v operator.
>> From 'help test' in bash:
>>
>> -v VAR True if the shell variable VAR is set.
>>
>> For which the OP's syntax is (also) obviously wrong.
>
> I'm not using the -v operator 'test' command, instead, here is the -v parameter of 'command':

I know you're not *deliberately* using the -v operator of the test
command, but when you wrote:

$ test ! command -v git

you showed us an invocation of "test" that (a) would not invoke the
"command" builtin and (b) could have been a valid invocation of "test"
*if* "test" had "-v" as a binary operator. I know you intended the "-v"
to be an argument to "command", but I initially ignored that.

At that time, you had not yet told us what you were trying to do. You
had only showed us several incorrect commands, some of which you wrongly
thought were correct. I had a pretty good idea what you intended, but I
chose to (a) explain what the incorrect commands you showed us actually
do and (b) prompt you to step back and tell us what you were trying to do.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

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

<87ee4wmlty.fsf@nosuchdomain.example.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.unix.shell
Subject: Re: bash: test: -v: binary operator expected
Date: Mon, 24 Jan 2022 21:22:01 -0800
Organization: None to speak of
Lines: 38
Message-ID: <87ee4wmlty.fsf@nosuchdomain.example.com>
References: <fd59c913-a21b-4120-95fb-f90ef611885cn@googlegroups.com>
<87y235oqe5.fsf@nosuchdomain.example.com>
<j5810lF492U1@mid.individual.net>
<4c40e948-5704-4888-9762-552a48c52a0an@googlegroups.com>
<op.1gi4vspca3w0dxdave@hodgins.homeip.net>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="fbd031f938b902ca86c8b061f35a7f8c";
logging-data="5351"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Q4k3n300OdAiS4AEJp03F"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:frCkOceMreyHple2QIQ/KDRuMPw=
sha1:noNtZds5TpwzLJwAq2PhUzI68CQ=
 by: Keith Thompson - Tue, 25 Jan 2022 05:22 UTC

"David W. Hodgins" <dwhodgins@nomail.afraid.org> writes:
> On Mon, 24 Jan 2022 20:26:36 -0500, hongy...@gmail.com <hongyi.zhao@gmail.com> wrote:
>> On Tuesday, January 25, 2022 at 12:04:43 AM UTC+8, John-Paul Stewart wrote:
>>> On 2022-01-23 20:48, 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.
>>> That depends on which 'test' you're using. The bash built-in 'test'
>>> (which the OP appears to be using) does have a (unary) -v operator.
>>> From 'help test' in bash:
>>>
>>> -v VAR True if the shell variable VAR is set.
>>>
>>> For which the OP's syntax is (also) obviously wrong.
>>
>> I'm not using the -v operator 'test' command, instead, here is the -v parameter of 'command':
>>
>> $ help command
>> -v print a description of COMMAND similar to the `type' builtin
>>
>> So, I really don't understand why you give the comments above.
>
> In order to avoid having the -v option be interpreted as an option passed to the
> test command, the "command -v git" must be passed as a single string to the test
> command. That's done by enclosing command -v git in quotes.
> test ! "command -v git"

That would be valid but useless. It checks whether the string
"command -v git" is empty.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

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

<a09dd35c-2ca1-4ede-89a3-b2c654f2f4dan@googlegroups.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:6214:2349:: with SMTP id hu9mr18018857qvb.93.1643095859563;
Mon, 24 Jan 2022 23:30:59 -0800 (PST)
X-Received: by 2002:a05:620a:244d:: with SMTP id h13mr13586575qkn.693.1643095859373;
Mon, 24 Jan 2022 23:30:59 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!feeder1.feed.usenet.farm!feed.usenet.farm!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Mon, 24 Jan 2022 23:30:59 -0800 (PST)
In-Reply-To: <87ee4wmlty.fsf@nosuchdomain.example.com>
Injection-Info: google-groups.googlegroups.com; posting-host=139.59.109.137; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 139.59.109.137
References: <fd59c913-a21b-4120-95fb-f90ef611885cn@googlegroups.com>
<87y235oqe5.fsf@nosuchdomain.example.com> <j5810lF492U1@mid.individual.net>
<4c40e948-5704-4888-9762-552a48c52a0an@googlegroups.com> <op.1gi4vspca3w0dxdave@hodgins.homeip.net>
<87ee4wmlty.fsf@nosuchdomain.example.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a09dd35c-2ca1-4ede-89a3-b2c654f2f4dan@googlegroups.com>
Subject: Re: bash: test: -v: binary operator expected
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Tue, 25 Jan 2022 07:30:59 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 3092
 by: hongy...@gmail.com - Tue, 25 Jan 2022 07:30 UTC

On Tuesday, January 25, 2022 at 1:22:06 PM UTC+8, Keith Thompson wrote:
> "David W. Hodgins" <dwho...@nomail.afraid.org> writes:
> > On Mon, 24 Jan 2022 20:26:36 -0500, hongy...@gmail.com <hongy...@gmail.com> wrote:
> >> On Tuesday, January 25, 2022 at 12:04:43 AM UTC+8, John-Paul Stewart wrote:
> >>> On 2022-01-23 20:48, 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.
> >>> That depends on which 'test' you're using. The bash built-in 'test'
> >>> (which the OP appears to be using) does have a (unary) -v operator.
> >>> From 'help test' in bash:
> >>>
> >>> -v VAR True if the shell variable VAR is set.
> >>>
> >>> For which the OP's syntax is (also) obviously wrong.
> >>
> >> I'm not using the -v operator 'test' command, instead, here is the -v parameter of 'command':
> >>
> >> $ help command
> >> -v print a description of COMMAND similar to the `type' builtin
> >>
> >> So, I really don't understand why you give the comments above.
> >
> > In order to avoid having the -v option be interpreted as an option passed to the
> > test command, the "command -v git" must be passed as a single string to the test
> > command. That's done by enclosing command -v git in quotes.
> > test ! "command -v git"
> That would be valid but useless. It checks whether the string
> "command -v git" is empty.

From where can I find the specification that running test on an empty string will return 1, as denoted by the following:

$ test ''; echo $?
1

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

<sso9se$e6s$1@dont-email.me>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: bash: test: -v: binary operator expected
Date: Tue, 25 Jan 2022 08:46:21 +0100
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <sso9se$e6s$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>
<op.1gi4vspca3w0dxdave@hodgins.homeip.net>
<87ee4wmlty.fsf@nosuchdomain.example.com>
<a09dd35c-2ca1-4ede-89a3-b2c654f2f4dan@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 25 Jan 2022 07:46:22 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="27110164bcad33ee6313c1b2114bb1ea";
logging-data="14556"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18i6c20hU1rvgy1uu9Tl4lD"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:ldrjaHxIeRFqsXyATrvcXPtwGsg=
In-Reply-To: <a09dd35c-2ca1-4ede-89a3-b2c654f2f4dan@googlegroups.com>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Tue, 25 Jan 2022 07:46 UTC

On 25.01.2022 08:30, hongy...@gmail.com wrote:
>
> From where can I find the specification that running test on an empty

Have you tried the man pages, have you tried the POSIX specification?
You may recall that I provided easy to use links some time ago - but
wait, it was already three(!) days ago, certainly too long to recall.

> string will return 1, as denoted by the following:
>
> $ test ''; echo $? 1
>

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

<3bbbe0e8-80a4-40ae-95da-353d618339cfn@googlegroups.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:622a:60c:: with SMTP id z12mr11621597qta.670.1643113564209;
Tue, 25 Jan 2022 04:26:04 -0800 (PST)
X-Received: by 2002:ac8:5e50:: with SMTP id i16mr1275461qtx.145.1643113564038;
Tue, 25 Jan 2022 04:26:04 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!border1.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: Tue, 25 Jan 2022 04:26:03 -0800 (PST)
In-Reply-To: <a09dd35c-2ca1-4ede-89a3-b2c654f2f4dan@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=62.249.217.89; posting-account=FHqkeAoAAACbOpBCHa7K6JTmToKlWNDp
NNTP-Posting-Host: 62.249.217.89
References: <fd59c913-a21b-4120-95fb-f90ef611885cn@googlegroups.com>
<87y235oqe5.fsf@nosuchdomain.example.com> <j5810lF492U1@mid.individual.net>
<4c40e948-5704-4888-9762-552a48c52a0an@googlegroups.com> <op.1gi4vspca3w0dxdave@hodgins.homeip.net>
<87ee4wmlty.fsf@nosuchdomain.example.com> <a09dd35c-2ca1-4ede-89a3-b2c654f2f4dan@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <3bbbe0e8-80a4-40ae-95da-353d618339cfn@googlegroups.com>
Subject: Re: bash: test: -v: binary operator expected
From: guinness...@gmail.com (Tony Oliver)
Injection-Date: Tue, 25 Jan 2022 12:26:04 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 34
 by: Tony Oliver - Tue, 25 Jan 2022 12:26 UTC

On Tuesday, 25 January 2022 at 07:31:01 UTC, hongy...@gmail.com wrote:
<snip>
> From where can I find the specification that running test on
> an empty string will return 1, as denoted by the following:
>
> $ test ''; echo $?
> 1

RTFM...

If you're using bash, enter the command
man bash

Search for CONDITIONAL EXPRESSIONS

Read the opening paragraphs (*PLEASE*) and then scroll down
through all the test / [ / [[ options until you get to this:

string
-n string
True if the length of string is non-zero.

And there you have it.

For the non-builtin 'test' executable, enter
man test
or
man [

Here, you will find

-n STRING
the length of STRING is nonzero

STRING equivalent to -n STRING

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

<d894c3f9-1a37-420e-99a9-7d306b62da2an@googlegroups.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:622a:589:: with SMTP id c9mr10766297qtb.58.1643117576259;
Tue, 25 Jan 2022 05:32:56 -0800 (PST)
X-Received: by 2002:a05:622a:609:: with SMTP id z9mr16716019qta.256.1643117576103;
Tue, 25 Jan 2022 05:32:56 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!border1.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: Tue, 25 Jan 2022 05:32:55 -0800 (PST)
In-Reply-To: <3bbbe0e8-80a4-40ae-95da-353d618339cfn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=143.198.81.105; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 143.198.81.105
References: <fd59c913-a21b-4120-95fb-f90ef611885cn@googlegroups.com>
<87y235oqe5.fsf@nosuchdomain.example.com> <j5810lF492U1@mid.individual.net>
<4c40e948-5704-4888-9762-552a48c52a0an@googlegroups.com> <op.1gi4vspca3w0dxdave@hodgins.homeip.net>
<87ee4wmlty.fsf@nosuchdomain.example.com> <a09dd35c-2ca1-4ede-89a3-b2c654f2f4dan@googlegroups.com>
<3bbbe0e8-80a4-40ae-95da-353d618339cfn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d894c3f9-1a37-420e-99a9-7d306b62da2an@googlegroups.com>
Subject: Re: bash: test: -v: binary operator expected
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Tue, 25 Jan 2022 13:32:56 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 41
 by: hongy...@gmail.com - Tue, 25 Jan 2022 13:32 UTC

On Tuesday, January 25, 2022 at 8:26:06 PM UTC+8, Tony Oliver wrote:
> On Tuesday, 25 January 2022 at 07:31:01 UTC, hongy...@gmail.com wrote:
> <snip>
> > From where can I find the specification that running test on
> > an empty string will return 1, as denoted by the following:
> >
> > $ test ''; echo $?
> > 1
> RTFM...
>
> If you're using bash, enter the command
> man bash
>
> Search for CONDITIONAL EXPRESSIONS
>
> Read the opening paragraphs (*PLEASE*) and then scroll down
> through all the test / [ / [[ options until you get to this:
>
> string
> -n string
> True if the length of string is non-zero.
>
> And there you have it.
>
> For the non-builtin 'test' executable, enter
> man test
> or
> man [
>
> Here, you will find
>
> -n STRING
> the length of STRING is nonzero
>
> STRING equivalent to -n STRING

Thank you, and some more to add:

$ help test | grep -A1 -- '-n STRING'
-n STRING
STRING True if string is not empty.

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

<ssp5jg$4eu$1@dont-email.me>

 copy mid

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

 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: Tue, 25 Jan 2022 15:39:28 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 58
Message-ID: <ssp5jg$4eu$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>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 25 Jan 2022 15:39:28 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="7da42e34849a54dc7c48b42dcb8c29f2";
logging-data="4574"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ncK7+YTBrHA8uhgtzEMA9o9UAJTaR4MM="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:+YULAC9ZvQ1MuqhISsAbCN5Km0U=
 by: Lew Pitcher - Tue, 25 Jan 2022 15:39 UTC

On Mon, 24 Jan 2022 17:26:36 -0800, hongy...@gmail.com wrote:

> On Tuesday, January 25, 2022 at 12:04:43 AM UTC+8, John-Paul Stewart wrote:
>> On 2022-01-23 20:48, 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.
>> That depends on which 'test' you're using. The bash built-in 'test'
>> (which the OP appears to be using) does have a (unary) -v operator.
>> From 'help test' in bash:
>>
>> -v VAR True if the shell variable VAR is set.
>>
>> For which the OP's syntax is (also) obviously wrong.
>
> I'm not using the -v operator 'test' command, instead, here is the -v parameter of 'command':

No, you are NOT using the -v parameter of 'command'. That may have been
your intention, but that's NOT what you did.

The builtin test command treats it's parameters as an expression.
In your case
test ! command -v git
you gave test four parameters:
a '!', instructing test to /complement/ the results of the
following expression

a string 'command', which would be the left hand side of
a "binary" expression

a string '-v', which would be the "operator" of a "binary"
expression, and

a string 'git', which would be the right hand side of a
"binary" expression

By issuing the error message
bash: test: -v: binary operator expected
bash tells you that the builtin[1] test encountered an unexpected
and invalid '-v' operator (instead of one of the "known" binary
operators) between the 'command' string and the 'git' string.

[1] by issuing the error as "bash: test:", bash has confirmed
that you invoked the bash builtin test. Had you used the test(1)
binary, bash would not have inserted the "bash: " into the error
message, and instead issued
test: '-v': binary operator expected

HTH
--
Lew Pitcher
"In Skills, We Trust"

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

<j5b2snFi7q4U1@mid.individual.net>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: jpstew...@personalprojects.net (John-Paul Stewart)
Newsgroups: comp.unix.shell
Subject: Re: bash: test: -v: binary operator expected
Date: Tue, 25 Jan 2022 14:55:02 -0500
Lines: 39
Message-ID: <j5b2snFi7q4U1@mid.individual.net>
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>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-Trace: individual.net AOLh+2bx4RX3SB/eaGRTKw6q3BcmMKIvxVOQokW3stnGZpZAan
Cancel-Lock: sha1:+f9oE/pBBids92jxf0uolqEIJAg=
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Content-Language: en-CA
In-Reply-To: <ssp5jg$4eu$1@dont-email.me>
 by: John-Paul Stewart - Tue, 25 Jan 2022 19:55 UTC

On 2022-01-25 10:39, Lew Pitcher wrote:
> On Mon, 24 Jan 2022 17:26:36 -0800, hongy...@gmail.com wrote:
>> On Tuesday, January 25, 2022 at 12:04:43 AM UTC+8, John-Paul Stewart wrote:
>>> On 2022-01-23 20:48, 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.
>>> That depends on which 'test' you're using. The bash built-in 'test'
>>> (which the OP appears to be using) does have a (unary) -v operator.
>>> From 'help test' in bash:
>>>
>>> -v VAR True if the shell variable VAR is set.
>>>
>>> For which the OP's syntax is (also) obviously wrong.
>>
>> I'm not using the -v operator 'test' command, instead, here is the -v
>> parameter of 'command':
>
> No, you are NOT using the -v parameter of 'command'. That may have been
> your intention, but that's NOT what you did.
[snip]
> [1] by issuing the error as "bash: test:", bash has confirmed
> that you invoked the bash builtin test. Had you used the test(1)
> binary, bash would not have inserted the "bash: " into the error
> message, and instead issued
> test: '-v': binary operator expected

In addition, the error message is explicitly saying that it was 'test'
that was (mis-)interpreting the -v operator, rather than it being parsed
as an option to 'command'.

The mention of 'test' in the error message should have been a big clue
to the OP that the line was not being interpreted the way he expected.

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

<84a5462d-f043-4785-b520-616d01a115acn@googlegroups.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:620a:29d3:: with SMTP id s19mr16699420qkp.730.1643156956703;
Tue, 25 Jan 2022 16:29:16 -0800 (PST)
X-Received: by 2002:a05:6214:2a82:: with SMTP id jr2mr21890060qvb.79.1643156956562;
Tue, 25 Jan 2022 16:29:16 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Tue, 25 Jan 2022 16:29:16 -0800 (PST)
In-Reply-To: <ssp5jg$4eu$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=139.59.109.137; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 139.59.109.137
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>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <84a5462d-f043-4785-b520-616d01a115acn@googlegroups.com>
Subject: Re: bash: test: -v: binary operator expected
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Wed, 26 Jan 2022 00:29:16 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 4038
 by: hongy...@gmail.com - Wed, 26 Jan 2022 00:29 UTC

On Tuesday, January 25, 2022 at 11:39:33 PM UTC+8, Lew Pitcher wrote:
> On Mon, 24 Jan 2022 17:26:36 -0800, hongy...@gmail.com wrote:
>
> > On Tuesday, January 25, 2022 at 12:04:43 AM UTC+8, John-Paul Stewart wrote:
> >> On 2022-01-23 20:48, 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.
> >> That depends on which 'test' you're using. The bash built-in 'test'
> >> (which the OP appears to be using) does have a (unary) -v operator.
> >> From 'help test' in bash:
> >>
> >> -v VAR True if the shell variable VAR is set.
> >>
> >> For which the OP's syntax is (also) obviously wrong.
> >
> > I'm not using the -v operator 'test' command, instead, here is the -v parameter of 'command':
> No, you are NOT using the -v parameter of 'command'. That may have been
> your intention, but that's NOT what you did.
>
> The builtin test command treats it's parameters as an expression.
> In your case
> test ! command -v git
> you gave test four parameters:
> a '!', instructing test to /complement/ the results of the
> following expression
>
> a string 'command', which would be the left hand side of
> a "binary" expression
>
> a string '-v', which would be the "operator" of a "binary"
> expression, and
>
> a string 'git', which would be the right hand side of a
> "binary" expression
>
> By issuing the error message
> bash: test: -v: binary operator expected
> bash tells you that the builtin[1] test encountered an unexpected
> and invalid '-v' operator (instead of one of the "known" binary
> operators) between the 'command' string and the 'git' string.

Thank you for your in-depth analysis. I checked and confirmed with the following tests:

$ ( set -x ; test ! command -v git )
+ test '!' command -v git
bash: test: -v: binary operator expected
$ ( set -x ; test ! 'command -v git' )
+ test '!' 'command -v git'
$ ( set -x ; test ! "command -v git" )
+ test '!' 'command -v git'


> [1] by issuing the error as "bash: test:", bash has confirmed
> that you invoked the bash builtin test. Had you used the test(1)
> binary, bash would not have inserted the "bash: " into the error
> message, and instead issued
> test: '-v': binary operator expected

I confirmed your above conclusion:
$ /bin/test command -v git
/bin/test: ā€˜-vā€™: binary operator expected

HZ

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

<4b4077ad-4bd0-47c8-83ad-52f1afbe670en@googlegroups.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a37:9e51:: with SMTP id h78mr3014451qke.179.1643157151038;
Tue, 25 Jan 2022 16:32:31 -0800 (PST)
X-Received: by 2002:a05:620a:4455:: with SMTP id w21mr16809235qkp.306.1643157150907;
Tue, 25 Jan 2022 16:32:30 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!border1.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: Tue, 25 Jan 2022 16:32:30 -0800 (PST)
In-Reply-To: <j5b2snFi7q4U1@mid.individual.net>
Injection-Info: google-groups.googlegroups.com; posting-host=139.59.109.137; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 139.59.109.137
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>
<j5b2snFi7q4U1@mid.individual.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <4b4077ad-4bd0-47c8-83ad-52f1afbe670en@googlegroups.com>
Subject: Re: bash: test: -v: binary operator expected
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Wed, 26 Jan 2022 00:32:31 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 10
 by: hongy...@gmail.com - Wed, 26 Jan 2022 00:32 UTC

On Wednesday, January 26, 2022 at 3:55:08 AM UTC+8, John-Paul Stewart wrote:
> In addition, the error message is explicitly saying that it was 'test'
> that was (mis-)interpreting the -v operator, rather than it being parsed
> as an option to 'command'.
>
> The mention of 'test' in the error message should have been a big clue
> to the OP that the line was not being interpreted the way he expected.

Thank you for pointing out and emphasizing this.

HZ

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

<ssrct9$3mb$1@dont-email.me>

 copy mid

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

 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 11:56:09 +0000
Organization: A noiseless patient Spider
Lines: 82
Message-ID: <ssrct9$3mb$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>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 26 Jan 2022 11:56:25 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="b56770b0bd18cca8c8e04caea639168c";
logging-data="3787"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ZiZVF59qGRcyXi4Zf9alkZjd8VOOSUMY="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101
Thunderbird/52.2.1 Lightning/5.4
Cancel-Lock: sha1:sGCQU6VdtW2KBjW7h+83m+yQDIc=
In-Reply-To: <84a5462d-f043-4785-b520-616d01a115acn@googlegroups.com>
Content-Language: en-GB
 by: Chris Elvidge - Wed, 26 Jan 2022 11:56 UTC

On 26/01/2022 00:29, hongy...@gmail.com wrote:
> On Tuesday, January 25, 2022 at 11:39:33 PM UTC+8, Lew Pitcher wrote:
>> On Mon, 24 Jan 2022 17:26:36 -0800, hongy...@gmail.com wrote:
>>
>>> On Tuesday, January 25, 2022 at 12:04:43 AM UTC+8, John-Paul Stewart wrote:
>>>> On 2022-01-23 20:48, 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.
>>>> That depends on which 'test' you're using. The bash built-in 'test'
>>>> (which the OP appears to be using) does have a (unary) -v operator.
>>>> From 'help test' in bash:
>>>>
>>>> -v VAR True if the shell variable VAR is set.
>>>>
>>>> For which the OP's syntax is (also) obviously wrong.
>>>
>>> I'm not using the -v operator 'test' command, instead, here is the -v parameter of 'command':
>> No, you are NOT using the -v parameter of 'command'. That may have been
>> your intention, but that's NOT what you did.
>>
>> The builtin test command treats it's parameters as an expression.
>> In your case
>> test ! command -v git
>> you gave test four parameters:
>> a '!', instructing test to /complement/ the results of the
>> following expression
>>
>> a string 'command', which would be the left hand side of
>> a "binary" expression
>>
>> a string '-v', which would be the "operator" of a "binary"
>> expression, and
>>
>> a string 'git', which would be the right hand side of a
>> "binary" expression
>>
>> By issuing the error message
>> bash: test: -v: binary operator expected
>> bash tells you that the builtin[1] test encountered an unexpected
>> and invalid '-v' operator (instead of one of the "known" binary
>> operators) between the 'command' string and the 'git' string.
>
> Thank you for your in-depth analysis. I checked and confirmed with the following tests:
>
> $ ( set -x ; test ! command -v git )
> + test '!' command -v git
> bash: test: -v: binary operator expected
> $ ( set -x ; test ! 'command -v git' )
> + test '!' 'command -v git'
> $ ( set -x ; test ! "command -v git" )
> + test '!' 'command -v git'
>
>
>> [1] by issuing the error as "bash: test:", bash has confirmed
>> that you invoked the bash builtin test. Had you used the test(1)
>> binary, bash would not have inserted the "bash: " into the error
>> message, and instead issued
>> test: '-v': binary operator expected
>
> I confirmed your above conclusion:
>
> $ /bin/test command -v git
> /bin/test: ā€˜-vā€™: binary operator expected
>
> HZ
>

I know I'm stupid to ask this, but why do you insist on 'test'ing a
linux/unix command?
Surely:
command -v git && echo "git installed" || echo "git not installed"
would suffice.

--
Chris Elvidge
England

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

<490366be-d3f7-43fd-a636-e84574b27409n@googlegroups.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:6214:18cd:: with SMTP id cy13mr23615127qvb.57.1643201463215;
Wed, 26 Jan 2022 04:51:03 -0800 (PST)
X-Received: by 2002:a05:620a:400e:: with SMTP id h14mr17368438qko.233.1643201463004;
Wed, 26 Jan 2022 04:51:03 -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 04:51:02 -0800 (PST)
In-Reply-To: <ssrct9$3mb$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=139.59.109.137; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 139.59.109.137
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>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <490366be-d3f7-43fd-a636-e84574b27409n@googlegroups.com>
Subject: Re: bash: test: -v: binary operator expected
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Wed, 26 Jan 2022 12:51:03 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 13
 by: hongy...@gmail.com - Wed, 26 Jan 2022 12:51 UTC

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.

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

Agreed.

Pages:12
server_pubkey.txt

rocksolid light 0.9.7
clearnet tor