Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Though I'll admit readability suffers slightly... -- Larry Wall in <2969@jato.Jpl.Nasa.Gov>


devel / comp.unix.shell / Re: [ "$#" != "1" ] vs [ $# != 1 ]

SubjectAuthor
* [ "$#" != "1" ] vs [ $# != 1 ]hongy...@gmail.com
+- Re: [ "$#" != "1" ] vs [ $# != 1 ]Chris Elvidge
+* Re: [ "$#" != "1" ] vs [ $# != 1 ]Lew Pitcher
|`- Re: [ "$#" != "1" ] vs [ $# != 1 ]Kenny McCormack
+- Re: [ "$#" != "1" ] vs [ $# != 1 ]Kees Nuyt
+- Re: [ "$#" != "1" ] vs [ $# != 1 ]Janis Papanagnou
`* Re: [ "$#" != "1" ] vs [ $# != 1 ]hymie!
 `* Re: [ "$#" != "1" ] vs [ $# != 1 ]hongy...@gmail.com
  +* Re: [ "$#" != "1" ] vs [ $# != 1 ]Janis Papanagnou
  |`* Re: [ "$#" != "1" ] vs [ $# != 1 ]hongy...@gmail.com
  | `* Re: [ "$#" != "1" ] vs [ $# != 1 ]Janis Papanagnou
  |  `- Re: [ "$#" != "1" ] vs [ $# != 1 ]hongy...@gmail.com
  `* Re: [ "$#" != "1" ] vs [ $# != 1 ]Lew Pitcher
   +- Re: [ "$#" != "1" ] vs [ $# != 1 ]hongy...@gmail.com
   `* Re: [ "$#" != "1" ] vs [ $# != 1 ]Geoff Clare
    +- Re: [ "$#" != "1" ] vs [ $# != 1 ]Lew Pitcher
    +- Re: [ "$#" != "1" ] vs [ $# != 1 ]Kaz Kylheku
    `* Re: [ "$#" != "1" ] vs [ $# != 1 ]hongy...@gmail.com
     `* Re: [ "$#" != "1" ] vs [ $# != 1 ]Kees Nuyt
      `* Re: [ "$#" != "1" ] vs [ $# != 1 ]hongy...@gmail.com
       `* Re: [ "$#" != "1" ] vs [ $# != 1 ]Janis Papanagnou
        `* Re: [ "$#" != "1" ] vs [ $# != 1 ]hongy...@gmail.com
         `* Re: [ "$#" != "1" ] vs [ $# != 1 ]Kees Nuyt
          `- Re: [ "$#" != "1" ] vs [ $# != 1 ]hongy...@gmail.com

1
[ "$#" != "1" ] vs [ $# != 1 ]

<dc20a826-9f33-4269-a74f-43baeb0ed7ccn@googlegroups.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:622a:104d:b0:2f3:bc09:f05 with SMTP id f13-20020a05622a104d00b002f3bc090f05mr23044725qte.396.1652250697408;
Tue, 10 May 2022 23:31:37 -0700 (PDT)
X-Received: by 2002:a05:6214:c6f:b0:45a:a2f2:6d23 with SMTP id
t15-20020a0562140c6f00b0045aa2f26d23mr21513851qvj.55.1652250697230; Tue, 10
May 2022 23:31:37 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.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, 10 May 2022 23:31:37 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=203.175.13.156; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 203.175.13.156
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <dc20a826-9f33-4269-a74f-43baeb0ed7ccn@googlegroups.com>
Subject: [ "$#" != "1" ] vs [ $# != 1 ]
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Wed, 11 May 2022 06:31:37 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1416
 by: hongy...@gmail.com - Wed, 11 May 2022 06:31 UTC

I noticed the following example here [1]:

```
#!/bin/sh

if [ "$#" != "1" ]; then
echo "Usage: test.sh <string>"
exit 1
fi;

gap -r -b -q << EOI
LoadPackage( "CrystCat" );
DisplaySpaceGroupType( "$1" );
EOI
```

It seems that [ $# != 1 ] is enough. Why use [ "$#" != "1" ] here?

[1] https://stackoverflow.com/questions/13418849/how-can-i-call-gap-functions-from-a-shell-script

Regards,
HZ

Re: [ "$#" != "1" ] vs [ $# != 1 ]

<t5g8to$3bk$1@dont-email.me>

 copy mid

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

 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: [ "$#" != "1" ] vs [ $# != 1 ]
Date: Wed, 11 May 2022 13:07:20 +0100
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <t5g8to$3bk$1@dont-email.me>
References: <dc20a826-9f33-4269-a74f-43baeb0ed7ccn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 11 May 2022 12:07:21 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="69c15a987d80f6afcd4a02111713e74a";
logging-data="3444"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19SWvZQBr03w4HjnFJEtN5xfAbnBVeXwJ8="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101
Thunderbird/52.2.1 Lightning/5.4
Cancel-Lock: sha1:LA3kHBeVgPQUJ2NAqQkyC/HoZWI=
In-Reply-To: <dc20a826-9f33-4269-a74f-43baeb0ed7ccn@googlegroups.com>
Content-Language: en-GB
 by: Chris Elvidge - Wed, 11 May 2022 12:07 UTC

On 11/05/2022 07:31, hongy...@gmail.com wrote:
> I noticed the following example here [1]:
>
> ```
> #!/bin/sh
>
> if [ "$#" != "1" ]; then
> echo "Usage: test.sh <string>"
> exit 1
> fi;
>
> gap -r -b -q << EOI
> LoadPackage( "CrystCat" );
> DisplaySpaceGroupType( "$1" );
> EOI
> ```
>
> It seems that [ $# != 1 ] is enough. Why use [ "$#" != "1" ] here?
>
> [1] https://stackoverflow.com/questions/13418849/how-can-i-call-gap-functions-from-a-shell-script
>
> Regards,
> HZ
>

Why not try [ $# -ne 1 ] ?

--
Chris Elvidge
England

Re: [ "$#" != "1" ] vs [ $# != 1 ]

<t5g944$3ak$1@dont-email.me>

 copy mid

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

 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: [ "$#" != "1" ] vs [ $# != 1 ]
Date: Wed, 11 May 2022 12:10:44 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <t5g944$3ak$1@dont-email.me>
References: <dc20a826-9f33-4269-a74f-43baeb0ed7ccn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 11 May 2022 12:10:44 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5b27943a8c053cbf07b4691a8dbdfca2";
logging-data="3412"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/5+uzLI5FCG2kj1Z+3Dqmw8fuBti7zlEY="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:nbWM9O0IK6apCGeG87mPM5sxLto=
 by: Lew Pitcher - Wed, 11 May 2022 12:10 UTC

On Tue, 10 May 2022 23:31:37 -0700, hongy...@gmail.com wrote:

> I noticed the following example here [1]:
>
> ```
> #!/bin/sh
>
> if [ "$#" != "1" ]; then
> echo "Usage: test.sh <string>"
> exit 1
> fi;
>
> gap -r -b -q << EOI LoadPackage( "CrystCat" );
> DisplaySpaceGroupType( "$1" );
> EOI ```
>
> It seems that [ $# != 1 ] is enough. Why use [ "$#" != "1" ] here?

I see no /obvious/ reason.

On a (perhaps) related note, why did the author of that code snippet
use a string test rather than an an arithmetic test? To me, the
code snippet should read
if [ $# -ne 1 ]
then
echo 'Usage: test.sh <string>'
exit 1
fi

--
Lew Pitcher
"In Skills, We Trust"

Re: [ "$#" != "1" ] vs [ $# != 1 ]

<ji5n7hhojq02j8e1r5qd6a32lfptf9pqs1@dim53.demon.nl>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
From: k.n...@nospam.demon.nl (Kees Nuyt)
Newsgroups: comp.unix.shell
Subject: Re: [ "$#" != "1" ] vs [ $# != 1 ]
Date: Wed, 11 May 2022 14:16:58 +0200
Reply-To: k.nuyt@nospam.demon.nl
Message-ID: <ji5n7hhojq02j8e1r5qd6a32lfptf9pqs1@dim53.demon.nl>
References: <dc20a826-9f33-4269-a74f-43baeb0ed7ccn@googlegroups.com>
User-Agent: ForteAgent/7.10.32.1214
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Organization: KPN B.V.
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.uzoreto.com!feeder.usenetexpress.com!tr2.eu1.usenetexpress.com!94.232.112.245.MISMATCH!abe005.abavia.com!abp001.abavia.com!news.kpn.nl!not-for-mail
Lines: 27
Injection-Date: Wed, 11 May 2022 14:16:59 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
 by: Kees Nuyt - Wed, 11 May 2022 12:16 UTC

On Tue, 10 May 2022 23:31:37 -0700 (PDT), "hongy...@gmail.com"
<hongyi.zhao@gmail.com> wrote:

> I noticed the following example here [1]:
>
> ```
> #!/bin/sh
> if [ "$#" != "1" ]; then
> echo "Usage: test.sh <string>"
> exit 1
> fi;
>
> It seems that [ $# != 1 ] is enough. Why use [ "$#" != "1" ] here?

Both are possible. If they had written:
:: [ $# != 1 ]
you might have asked:
:: It seems that [ "$#" != "1" ] is enough.
:: Why use [ $# != 1 ] here?

Not surprisingly, there is even another way to do it:
:: [ $# -ne 1 ]

I hope this helps
--
Kees Nuyt

Re: [ "$#" != "1" ] vs [ $# != 1 ]

<t5gch3$dlo$1@dont-email.me>

 copy mid

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

 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: [ "$#" != "1" ] vs [ $# != 1 ]
Date: Wed, 11 May 2022 15:08:50 +0200
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <t5gch3$dlo$1@dont-email.me>
References: <dc20a826-9f33-4269-a74f-43baeb0ed7ccn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 11 May 2022 13:08:51 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="0747409c81dfd2b2de524a66d0b5f135";
logging-data="14008"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+q/276/7T8RM1NAi7dCsqR"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:nEEZGyQETz00vvbfb2ff700ZhlE=
In-Reply-To: <dc20a826-9f33-4269-a74f-43baeb0ed7ccn@googlegroups.com>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Wed, 11 May 2022 13:08 UTC

On 11.05.2022 08:31, hongy...@gmail.com wrote:
> I noticed the following example here [1]:
>
> ```
> #!/bin/sh
>
> if [ "$#" != "1" ]; then
> echo "Usage: test.sh <string>"
> exit 1
> fi;
>
> gap -r -b -q << EOI
> LoadPackage( "CrystCat" );
> DisplaySpaceGroupType( "$1" );
> EOI
> ```

Why did you post this here-doc code which is completely unrelated
to your question?

>
> It seems that [ $# != 1 ] is enough. Why use [ "$#" != "1" ] here?

On Stackoverflow I experienced a couple of "experts" that spread
the wisdom of "always quote variable expansions"; this is fine as
a rule of thumb (but annoying if you know when you need quotes and
when not). This may have been the reason but is of course completely
unnecessary.

Since the shebang line is qualifying '/bin/sh' the best answer (as
already suggested) is probably to use [ $# -ne 1 ]

Janis

> [1] https://stackoverflow.com/questions/13418849/how-can-i-call-gap-functions-from-a-shell-script
>
> Regards,
> HZ
>

Re: [ "$#" != "1" ] vs [ $# != 1 ]

<t5go88$304i$1@news.xmission.com>

 copy mid

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

 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: [ "$#" != "1" ] vs [ $# != 1 ]
Date: Wed, 11 May 2022 16:28:56 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <t5go88$304i$1@news.xmission.com>
References: <dc20a826-9f33-4269-a74f-43baeb0ed7ccn@googlegroups.com> <t5g944$3ak$1@dont-email.me>
Injection-Date: Wed, 11 May 2022 16:28:56 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="98450"; 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 - Wed, 11 May 2022 16:28 UTC

In article <t5g944$3ak$1@dont-email.me>,
Lew Pitcher <lew.pitcher@digitalfreehold.ca> wrote:
....
>I see no /obvious/ reason.
>
>On a (perhaps) related note, why did the author of that code snippet
>use a string test rather than an an arithmetic test? To me, the
>code snippet should read

Like you said above, there is no difference.

And there are about thousand other ways of doing it as well. Take your pick...

--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/Rorschach

Re: [ "$#" != "1" ] vs [ $# != 1 ]

<slrnt7o4qn.b3l.hymie@nasalinux.net>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx09.iad.POSTED!not-for-mail
Newsgroups: comp.unix.shell
From: hym...@nasalinux.net (hymie!)
Subject: Re: [ "$#" != "1" ] vs [ $# != 1 ]
References: <dc20a826-9f33-4269-a74f-43baeb0ed7ccn@googlegroups.com>
Organization: Eric Conspiracy Secret Labs
User-Agent: slrn/pre1.0.4-6 (Linux)
Message-ID: <slrnt7o4qn.b3l.hymie@nasalinux.net>
Lines: 22
X-Complaints-To: abuse@usenet-news.net
NNTP-Posting-Date: Wed, 11 May 2022 19:49:43 UTC
Date: Wed, 11 May 2022 19:49:43 GMT
X-Received-Bytes: 1119
 by: hymie! - Wed, 11 May 2022 19:49 UTC

In our last episode, the evil Dr. Lacto had captured our hero,
hongy...@gmail.com <hongyi.zhao@gmail.com>, who said:
> I noticed the following example here [1]:
>
> if [ "$#" != "1" ]; then
>
> It seems that [ $# != 1 ] is enough. Why use [ "$#" != "1" ] here?

Consider a different variable

if [ $FOO != 1 ] ; then

if $FOO is completely uninitialized, then this will expand to

if [ != 1 ] ; then

which is a syntax error.

That is the reason that I, personally, almost always use the extra
quotation marks.

--hymie! http://nasalinux.net/~hymie hymie@nasalinux.net

Re: [ "$#" != "1" ] vs [ $# != 1 ]

<4a9a6179-6a26-48a9-bda5-76dd1b5f4761n@googlegroups.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:ac8:110a:0:b0:2f1:ea84:b84 with SMTP id c10-20020ac8110a000000b002f1ea840b84mr26192147qtj.463.1652319325009;
Wed, 11 May 2022 18:35:25 -0700 (PDT)
X-Received: by 2002:a05:620a:2844:b0:680:d4a4:ced8 with SMTP id
h4-20020a05620a284400b00680d4a4ced8mr20540558qkp.290.1652319324831; Wed, 11
May 2022 18:35:24 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Wed, 11 May 2022 18:35:24 -0700 (PDT)
In-Reply-To: <slrnt7o4qn.b3l.hymie@nasalinux.net>
Injection-Info: google-groups.googlegroups.com; posting-host=203.175.13.156; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 203.175.13.156
References: <dc20a826-9f33-4269-a74f-43baeb0ed7ccn@googlegroups.com> <slrnt7o4qn.b3l.hymie@nasalinux.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <4a9a6179-6a26-48a9-bda5-76dd1b5f4761n@googlegroups.com>
Subject: Re: [ "$#" != "1" ] vs [ $# != 1 ]
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Thu, 12 May 2022 01:35:25 +0000
Content-Type: text/plain; charset="UTF-8"
 by: hongy...@gmail.com - Thu, 12 May 2022 01:35 UTC

On Thursday, May 12, 2022 at 3:49:49 AM UTC+8, hymie! wrote:
> In our last episode, the evil Dr. Lacto had captured our hero,
> hongy...@gmail.com <hongy...@gmail.com>, who said:
> > I noticed the following example here [1]:
> >
> > if [ "$#" != "1" ]; then
> >
> > It seems that [ $# != 1 ] is enough. Why use [ "$#" != "1" ] here?
> Consider a different variable
>
> if [ $FOO != 1 ] ; then
>
> if $FOO is completely uninitialized, then this will expand to
>
> if [ != 1 ] ; then
>
> which is a syntax error.
>
> That is the reason that I, personally, almost always use the extra
> quotation marks.

As commented by others in this thread, the following method will avoid this problem?

[ $# -ne 1 ]
>
> --hymie! http://nasalinux.net/~hymie hy...@nasalinux.net

Re: [ "$#" != "1" ] vs [ $# != 1 ]

<t5hpat$bd0$1@dont-email.me>

 copy mid

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

 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: [ "$#" != "1" ] vs [ $# != 1 ]
Date: Thu, 12 May 2022 03:53:32 +0200
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <t5hpat$bd0$1@dont-email.me>
References: <dc20a826-9f33-4269-a74f-43baeb0ed7ccn@googlegroups.com>
<slrnt7o4qn.b3l.hymie@nasalinux.net>
<4a9a6179-6a26-48a9-bda5-76dd1b5f4761n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 12 May 2022 01:53:33 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="6bb60475e5580a2e2eb5a28014aa8437";
logging-data="11680"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/FMAqI4ebg+iR/HHLVzDiE"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:Wl1cjj/eCAQGTtpWuOdsgZjzAnA=
In-Reply-To: <4a9a6179-6a26-48a9-bda5-76dd1b5f4761n@googlegroups.com>
 by: Janis Papanagnou - Thu, 12 May 2022 01:53 UTC

On 12.05.2022 03:35, hongy...@gmail.com wrote:
> On Thursday, May 12, 2022 at 3:49:49 AM UTC+8, hymie! wrote:
>> In our last episode, the evil Dr. Lacto had captured our hero,
>> hongy...@gmail.com <hongy...@gmail.com>, who said:
>>> I noticed the following example here [1]:
>>>
>>> if [ "$#" != "1" ]; then
>>>
>>> It seems that [ $# != 1 ] is enough. Why use [ "$#" != "1" ] here?
>> Consider a different variable
>>
>> if [ $FOO != 1 ] ; then
>>
>> if $FOO is completely uninitialized, then this will expand to
>>
>> if [ != 1 ] ; then
>>
>> which is a syntax error.
>>
>> That is the reason that I, personally, almost always use the extra
>> quotation marks.
>
> As commented by others in this thread, the following method will avoid this problem?
>
> [ $# -ne 1 ]

$FOO is an arbitrary user defined (or undefined) variable.
$# is a numeric variable set by the shell.

So [ $FOO -ne 1 ] will not avoid the issue.

Of course just trying that code would be faster than writing a post.

>
>>
>> --hymie! http://nasalinux.net/~hymie hy...@nasalinux.net

Re: [ "$#" != "1" ] vs [ $# != 1 ]

<ee3cbc7d-2189-4111-8209-70398a0612f3n@googlegroups.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:620a:298c:b0:6a0:94d2:2e39 with SMTP id r12-20020a05620a298c00b006a094d22e39mr13575078qkp.278.1652326934166;
Wed, 11 May 2022 20:42:14 -0700 (PDT)
X-Received: by 2002:a05:622a:5d1:b0:2f3:c5fc:68fc with SMTP id
d17-20020a05622a05d100b002f3c5fc68fcmr26823740qtb.284.1652326933970; Wed, 11
May 2022 20:42:13 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Wed, 11 May 2022 20:42:13 -0700 (PDT)
In-Reply-To: <t5hpat$bd0$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=203.175.13.156; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 203.175.13.156
References: <dc20a826-9f33-4269-a74f-43baeb0ed7ccn@googlegroups.com>
<slrnt7o4qn.b3l.hymie@nasalinux.net> <4a9a6179-6a26-48a9-bda5-76dd1b5f4761n@googlegroups.com>
<t5hpat$bd0$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ee3cbc7d-2189-4111-8209-70398a0612f3n@googlegroups.com>
Subject: Re: [ "$#" != "1" ] vs [ $# != 1 ]
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Thu, 12 May 2022 03:42:14 +0000
Content-Type: text/plain; charset="UTF-8"
 by: hongy...@gmail.com - Thu, 12 May 2022 03:42 UTC

On Thursday, May 12, 2022 at 9:53:39 AM UTC+8, Janis Papanagnou wrote:
> On 12.05.2022 03:35, hongy...@gmail.com wrote:
> > On Thursday, May 12, 2022 at 3:49:49 AM UTC+8, hymie! wrote:
> >> In our last episode, the evil Dr. Lacto had captured our hero,
> >> hongy...@gmail.com <hongy...@gmail.com>, who said:
> >>> I noticed the following example here [1]:
> >>>
> >>> if [ "$#" != "1" ]; then
> >>>
> >>> It seems that [ $# != 1 ] is enough. Why use [ "$#" != "1" ] here?
> >> Consider a different variable
> >>
> >> if [ $FOO != 1 ] ; then
> >>
> >> if $FOO is completely uninitialized, then this will expand to
> >>
> >> if [ != 1 ] ; then
> >>
> >> which is a syntax error.
> >>
> >> That is the reason that I, personally, almost always use the extra
> >> quotation marks.
> >
> > As commented by others in this thread, the following method will avoid this problem?
> >
> > [ $# -ne 1 ]
> $FOO is an arbitrary user defined (or undefined) variable.
> $# is a numeric variable set by the shell.
>
> So [ $FOO -ne 1 ] will not avoid the issue.
>
> Of course just trying that code would be faster than writing a post.

Yes. All the problems discussed in this post can be illustrated by the following examples:

$ [ "$FOO" = 1 ]; echo $?
1 $ [ "$FOO" = "1" ]; echo $?
1 $ [ $FOO -ne 1 ]
bash: [: -ne: unary operator expected
$ [ "$FOO" -ne 1 ]
bash: [: : integer expression expected

But maybe this way can also help others.

Best,
HZ

> >
> >>
> >> --hymie! http://nasalinux.net/~hymie hy...@nasalinux.net

Re: [ "$#" != "1" ] vs [ $# != 1 ]

<t5j553$d1c$1@dont-email.me>

 copy mid

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

 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: [ "$#" != "1" ] vs [ $# != 1 ]
Date: Thu, 12 May 2022 14:21:23 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 50
Message-ID: <t5j553$d1c$1@dont-email.me>
References: <dc20a826-9f33-4269-a74f-43baeb0ed7ccn@googlegroups.com>
<slrnt7o4qn.b3l.hymie@nasalinux.net>
<4a9a6179-6a26-48a9-bda5-76dd1b5f4761n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 12 May 2022 14:21:23 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="a339f74e7c8f662423fa4a0523e5eeee";
logging-data="13356"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19AS4F1hXkxQ14mVkpV26Uy+aKFinBosv8="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:yhtJdjMJ6l/MGOYwMESvW/mkGPY=
 by: Lew Pitcher - Thu, 12 May 2022 14:21 UTC

On Wed, 11 May 2022 18:35:24 -0700, hongy...@gmail.com wrote:

> On Thursday, May 12, 2022 at 3:49:49 AM UTC+8, hymie! wrote:
>> In our last episode, the evil Dr. Lacto had captured our hero,
>> hongy...@gmail.com <hongy...@gmail.com>, who said:
>> > I noticed the following example here [1]:
>> >
>> > if [ "$#" != "1" ]; then
>> >
>> > It seems that [ $# != 1 ] is enough. Why use [ "$#" != "1" ] here?
>> Consider a different variable
>>
>> if [ $FOO != 1 ] ; then
>>
>> if $FOO is completely uninitialized, then this will expand to
>>
>> if [ != 1 ] ; then
>>
>> which is a syntax error.
>>
>> That is the reason that I, personally, almost always use the extra
>> quotation marks.
>
> As commented by others in this thread, the following method will avoid
> this problem?
>
> [ $# -ne 1 ]

As a specific solution, yes.

$# is guaranteed to contain a numeric count of the number of arguments
passed into a script. It *cannot* be empty, or contain space delimited
values, so bracketing it in doublequotes is redundant. Both sides of the
test contain a decimal values, so a numeric test (such as -ne) would be
appropriate.

OTOH, as a general solution, not so much.

In the test
[ $FOO -ne $BAR ]
neither $FOO nor $BAR provide the content guarantees that $# does (not
empty, not space delimited string, numeric value only) so it would be
prudent to bracket each with doublequotes. Also, given that neither
guarantees a numeric value, it would be prudent to use the != test
instead of the -ne test, making the /prudent/ test
[ "$FOO" != "$BAR" ]

--
Lew Pitcher
"In Skills, We Trust"

Re: [ "$#" != "1" ] vs [ $# != 1 ]

<t5k3ft$6kt$1@dont-email.me>

 copy mid

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

 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: [ "$#" != "1" ] vs [ $# != 1 ]
Date: Fri, 13 May 2022 00:59:09 +0200
Organization: A noiseless patient Spider
Lines: 66
Message-ID: <t5k3ft$6kt$1@dont-email.me>
References: <dc20a826-9f33-4269-a74f-43baeb0ed7ccn@googlegroups.com>
<slrnt7o4qn.b3l.hymie@nasalinux.net>
<4a9a6179-6a26-48a9-bda5-76dd1b5f4761n@googlegroups.com>
<t5hpat$bd0$1@dont-email.me>
<ee3cbc7d-2189-4111-8209-70398a0612f3n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 12 May 2022 22:59:09 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="098381810f89506340e15ae1985ec656";
logging-data="6813"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/catZfafxF3Wu+gPwySniS"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:7e9dhWCOTWOEjhyIrZAsyAsMvws=
In-Reply-To: <ee3cbc7d-2189-4111-8209-70398a0612f3n@googlegroups.com>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Thu, 12 May 2022 22:59 UTC

On 12.05.2022 05:42, hongy...@gmail.com wrote:
> On Thursday, May 12, 2022 at 9:53:39 AM UTC+8, Janis Papanagnou wrote:
>> On 12.05.2022 03:35, hongy...@gmail.com wrote:
>>> On Thursday, May 12, 2022 at 3:49:49 AM UTC+8, hymie! wrote:
>>>> In our last episode, the evil Dr. Lacto had captured our hero,
>>>> hongy...@gmail.com <hongy...@gmail.com>, who said:
>>>>> I noticed the following example here [1]:
>>>>>
>>>>> if [ "$#" != "1" ]; then
>>>>>
>>>>> It seems that [ $# != 1 ] is enough. Why use [ "$#" != "1" ] here?
>>>> Consider a different variable
>>>>
>>>> if [ $FOO != 1 ] ; then
>>>>
>>>> if $FOO is completely uninitialized, then this will expand to
>>>>
>>>> if [ != 1 ] ; then
>>>>
>>>> which is a syntax error.
>>>>
>>>> That is the reason that I, personally, almost always use the extra
>>>> quotation marks.
>>>
>>> As commented by others in this thread, the following method will avoid this problem?
>>>
>>> [ $# -ne 1 ]
>> $FOO is an arbitrary user defined (or undefined) variable.
>> $# is a numeric variable set by the shell.
>>
>> So [ $FOO -ne 1 ] will not avoid the issue.
>>
>> Of course just trying that code would be faster than writing a post.
>
> Yes. All the problems discussed in this post can be illustrated by the following examples:
>
> $ [ "$FOO" = 1 ]; echo $?
> 1
> $ [ "$FOO" = "1" ]; echo $?
> 1
> $ [ $FOO -ne 1 ]
> bash: [: -ne: unary operator expected
> $ [ "$FOO" -ne 1 ]
> bash: [: : integer expression expected

In your thread you have asked a question about using the test command
and quoting to address some issues and, based on some sample code from
the net, understand how it works best. In this context it is noteworthy
that (for own programs) you have more (and better) choices. Some of the
issues and caveats that the historic test command and shell's command
syntax with test has (which unfortunately is also the only standard
base for standard shell) are fixed or alleviated with the test syntax
[[...]] that the powerful "modern" shells (ksh, bash, zsh, maybe others
too) support. (In this vein inspect for arithmetic contexts also the
arithmetic command ((...)) construct.)

I suggest to try these contemporary constructs with code samples like
the ones you started with above, vary the data from undefined, empty,
defined, defined with spaces, use of shell-patterns for comparisons,
use various comparison operators (!=, ==, =) etc., compare it with the
old (standard) syntax, and observe the difference in behavior, the
consistency, whether it meets your expectations, or whether one or the
other surprises you. Then draw your conclusions.

Janis

Re: [ "$#" != "1" ] vs [ $# != 1 ]

<7870d2d3-ca92-43fa-a49f-cd35a1ad0576n@googlegroups.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a37:9442:0:b0:699:fd32:bc7d with SMTP id w63-20020a379442000000b00699fd32bc7dmr1980173qkd.615.1652403557919;
Thu, 12 May 2022 17:59:17 -0700 (PDT)
X-Received: by 2002:a37:5d2:0:b0:69f:a41b:9bda with SMTP id
201-20020a3705d2000000b0069fa41b9bdamr1908076qkf.761.1652403557742; Thu, 12
May 2022 17:59:17 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!2.eu.feeder.erje.net!feeder.erje.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Thu, 12 May 2022 17:59:17 -0700 (PDT)
In-Reply-To: <t5k3ft$6kt$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=103.149.249.8; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 103.149.249.8
References: <dc20a826-9f33-4269-a74f-43baeb0ed7ccn@googlegroups.com>
<slrnt7o4qn.b3l.hymie@nasalinux.net> <4a9a6179-6a26-48a9-bda5-76dd1b5f4761n@googlegroups.com>
<t5hpat$bd0$1@dont-email.me> <ee3cbc7d-2189-4111-8209-70398a0612f3n@googlegroups.com>
<t5k3ft$6kt$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <7870d2d3-ca92-43fa-a49f-cd35a1ad0576n@googlegroups.com>
Subject: Re: [ "$#" != "1" ] vs [ $# != 1 ]
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Fri, 13 May 2022 00:59:17 +0000
Content-Type: text/plain; charset="UTF-8"
 by: hongy...@gmail.com - Fri, 13 May 2022 00:59 UTC

On Friday, May 13, 2022 at 6:59:15 AM UTC+8, Janis Papanagnou wrote:
> On 12.05.2022 05:42, hongy...@gmail.com wrote:
> > On Thursday, May 12, 2022 at 9:53:39 AM UTC+8, Janis Papanagnou wrote:
> >> On 12.05.2022 03:35, hongy...@gmail.com wrote:
> >>> On Thursday, May 12, 2022 at 3:49:49 AM UTC+8, hymie! wrote:
> >>>> In our last episode, the evil Dr. Lacto had captured our hero,
> >>>> hongy...@gmail.com <hongy...@gmail.com>, who said:
> >>>>> I noticed the following example here [1]:
> >>>>>
> >>>>> if [ "$#" != "1" ]; then
> >>>>>
> >>>>> It seems that [ $# != 1 ] is enough. Why use [ "$#" != "1" ] here?
> >>>> Consider a different variable
> >>>>
> >>>> if [ $FOO != 1 ] ; then
> >>>>
> >>>> if $FOO is completely uninitialized, then this will expand to
> >>>>
> >>>> if [ != 1 ] ; then
> >>>>
> >>>> which is a syntax error.
> >>>>
> >>>> That is the reason that I, personally, almost always use the extra
> >>>> quotation marks.
> >>>
> >>> As commented by others in this thread, the following method will avoid this problem?
> >>>
> >>> [ $# -ne 1 ]
> >> $FOO is an arbitrary user defined (or undefined) variable.
> >> $# is a numeric variable set by the shell.
> >>
> >> So [ $FOO -ne 1 ] will not avoid the issue.
> >>
> >> Of course just trying that code would be faster than writing a post.
> >
> > Yes. All the problems discussed in this post can be illustrated by the following examples:
> >
> > $ [ "$FOO" = 1 ]; echo $?
> > 1
> > $ [ "$FOO" = "1" ]; echo $?
> > 1
> > $ [ $FOO -ne 1 ]
> > bash: [: -ne: unary operator expected
> > $ [ "$FOO" -ne 1 ]
> > bash: [: : integer expression expected
> In your thread you have asked a question about using the test command
> and quoting to address some issues and, based on some sample code from
> the net, understand how it works best. In this context it is noteworthy
> that (for own programs) you have more (and better) choices. Some of the
> issues and caveats that the historic test command and shell's command
> syntax with test has (which unfortunately is also the only standard
> base for standard shell) are fixed or alleviated with the test syntax
> [[...]] that the powerful "modern" shells (ksh, bash, zsh, maybe others
> too) support. (In this vein inspect for arithmetic contexts also the
> arithmetic command ((...)) construct.)
>
> I suggest to try these contemporary constructs with code samples like
> the ones you started with above, vary the data from undefined, empty,
> defined, defined with spaces, use of shell-patterns for comparisons,
> use various comparison operators (!=, ==, =) etc., compare it with the
> old (standard) syntax, and observe the difference in behavior, the
> consistency, whether it meets your expectations, or whether one or the
> other surprises you. Then draw your conclusions.

Thank you for your advice and suggestions.

> Janis
HZ

Re: [ "$#" != "1" ] vs [ $# != 1 ]

<d5234336-1ad9-4ed1-8d73-989b1275b0bfn@googlegroups.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:622a:1a9c:b0:2f3:d873:4acc with SMTP id s28-20020a05622a1a9c00b002f3d8734accmr2502646qtc.424.1652403683399;
Thu, 12 May 2022 18:01:23 -0700 (PDT)
X-Received: by 2002:a05:6214:519e:b0:45a:e487:54e with SMTP id
kl30-20020a056214519e00b0045ae487054emr2579896qvb.76.1652403682834; Thu, 12
May 2022 18:01:22 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Thu, 12 May 2022 18:01:22 -0700 (PDT)
In-Reply-To: <t5j553$d1c$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=203.175.13.152; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 203.175.13.152
References: <dc20a826-9f33-4269-a74f-43baeb0ed7ccn@googlegroups.com>
<slrnt7o4qn.b3l.hymie@nasalinux.net> <4a9a6179-6a26-48a9-bda5-76dd1b5f4761n@googlegroups.com>
<t5j553$d1c$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d5234336-1ad9-4ed1-8d73-989b1275b0bfn@googlegroups.com>
Subject: Re: [ "$#" != "1" ] vs [ $# != 1 ]
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Fri, 13 May 2022 01:01:23 +0000
Content-Type: text/plain; charset="UTF-8"
 by: hongy...@gmail.com - Fri, 13 May 2022 01:01 UTC

On Thursday, May 12, 2022 at 10:21:29 PM UTC+8, Lew Pitcher wrote:
> On Wed, 11 May 2022 18:35:24 -0700, hongy...@gmail.com wrote:
>
> > On Thursday, May 12, 2022 at 3:49:49 AM UTC+8, hymie! wrote:
> >> In our last episode, the evil Dr. Lacto had captured our hero,
> >> hongy...@gmail.com <hongy...@gmail.com>, who said:
> >> > I noticed the following example here [1]:
> >> >
> >> > if [ "$#" != "1" ]; then
> >> >
> >> > It seems that [ $# != 1 ] is enough. Why use [ "$#" != "1" ] here?
> >> Consider a different variable
> >>
> >> if [ $FOO != 1 ] ; then
> >>
> >> if $FOO is completely uninitialized, then this will expand to
> >>
> >> if [ != 1 ] ; then
> >>
> >> which is a syntax error.
> >>
> >> That is the reason that I, personally, almost always use the extra
> >> quotation marks.
> >
> > As commented by others in this thread, the following method will avoid
> > this problem?
> >
> > [ $# -ne 1 ]
> As a specific solution, yes.
>
> $# is guaranteed to contain a numeric count of the number of arguments
> passed into a script. It *cannot* be empty, or contain space delimited
> values, so bracketing it in doublequotes is redundant. Both sides of the
> test contain a decimal values, so a numeric test (such as -ne) would be
> appropriate.
>
> OTOH, as a general solution, not so much.
>
> In the test
> [ $FOO -ne $BAR ]
> neither $FOO nor $BAR provide the content guarantees that $# does (not
> empty, not space delimited string, numeric value only) so it would be
> prudent to bracket each with doublequotes. Also, given that neither
> guarantees a numeric value, it would be prudent to use the != test
> instead of the -ne test, making the /prudent/ test
> [ "$FOO" != "$BAR" ]

Thank you for your prudent analysis.

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

Re: [ "$#" != "1" ] vs [ $# != 1 ]

<04v1li-f0i.ln1@ID-313840.user.individual.net>

 copy mid

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

 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: geo...@clare.See-My-Signature.invalid (Geoff Clare)
Newsgroups: comp.unix.shell
Subject: Re: [ "$#" != "1" ] vs [ $# != 1 ]
Date: Fri, 13 May 2022 13:21:52 +0100
Lines: 14
Message-ID: <04v1li-f0i.ln1@ID-313840.user.individual.net>
References: <dc20a826-9f33-4269-a74f-43baeb0ed7ccn@googlegroups.com>
<slrnt7o4qn.b3l.hymie@nasalinux.net>
<4a9a6179-6a26-48a9-bda5-76dd1b5f4761n@googlegroups.com>
<t5j553$d1c$1@dont-email.me>
Reply-To: netnews@gclare.org.uk
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net 7II86Vw+D3zW1bs1xFup3gbsV48Zcu1ApdxBPwAz0iF05ztmAT
X-Orig-Path: ID-313840.user.individual.net!not-for-mail
Cancel-Lock: sha1:tj6ycGAbgjcvjUII5are8m0OL0k=
User-Agent: Pan/0.145 (Duplicitous mercenary valetism; d7e168a
git.gnome.org/pan2)
 by: Geoff Clare - Fri, 13 May 2022 12:21 UTC

Lew Pitcher wrote:

> $# is guaranteed to contain a numeric count of the number of arguments
> passed into a script. It *cannot* be empty, or contain space delimited
> values, so bracketing it in doublequotes is redundant.

Double quotes around $# are redundant only if there are no digits in IFS.

That would certainly be true for the case the OP asked about, where the
$# expansion was in the first command executed in the script. But it
can't be assumed to be true in general.

--
Geoff Clare <netnews@gclare.org.uk>

Re: [ "$#" != "1" ] vs [ $# != 1 ]

<t5lp49$tb3$1@dont-email.me>

 copy mid

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

 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: [ "$#" != "1" ] vs [ $# != 1 ]
Date: Fri, 13 May 2022 14:14:33 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <t5lp49$tb3$1@dont-email.me>
References: <dc20a826-9f33-4269-a74f-43baeb0ed7ccn@googlegroups.com>
<slrnt7o4qn.b3l.hymie@nasalinux.net>
<4a9a6179-6a26-48a9-bda5-76dd1b5f4761n@googlegroups.com>
<t5j553$d1c$1@dont-email.me>
<04v1li-f0i.ln1@ID-313840.user.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 13 May 2022 14:14:33 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="12ca17370a0e926a7e47ae1b395700e1";
logging-data="30051"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19vtYIVRN3lv5FKBxcNNYe9UdJrQ7wOPVs="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:P1MWbINv9VsYKYuSxeMR4O77El4=
 by: Lew Pitcher - Fri, 13 May 2022 14:14 UTC

On Fri, 13 May 2022 13:21:52 +0100, Geoff Clare wrote:

> Lew Pitcher wrote:
>
>> $# is guaranteed to contain a numeric count of the number of arguments
>> passed into a script. It *cannot* be empty, or contain space delimited
>> values, so bracketing it in doublequotes is redundant.
>
> Double quotes around $# are redundant only if there are no digits in
> IFS.

Good catch!

>
> That would certainly be true for the case the OP asked about, where the
> $# expansion was in the first command executed in the script. But it
> can't be assumed to be true in general.

--
Lew Pitcher
"In Skills, We Trust"

Re: [ "$#" != "1" ] vs [ $# != 1 ]

<20220513070709.539@kylheku.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 480-992-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell
Subject: Re: [ "$#" != "1" ] vs [ $# != 1 ]
Date: Fri, 13 May 2022 14:24:02 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <20220513070709.539@kylheku.com>
References: <dc20a826-9f33-4269-a74f-43baeb0ed7ccn@googlegroups.com>
<slrnt7o4qn.b3l.hymie@nasalinux.net>
<4a9a6179-6a26-48a9-bda5-76dd1b5f4761n@googlegroups.com>
<t5j553$d1c$1@dont-email.me> <04v1li-f0i.ln1@ID-313840.user.individual.net>
Injection-Date: Fri, 13 May 2022 14:24:02 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="c641d7ef37d47175de7a9e494bff9b8b";
logging-data="25720"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/C/qWIgjqQL55Q6S4JCPYjkSstf6nBfdY="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:rQLI5/lN0fN1EgNfd/Vf5IKqKWY=
 by: Kaz Kylheku - Fri, 13 May 2022 14:24 UTC

On 2022-05-13, Geoff Clare <geoff@clare.See-My-Signature.invalid> wrote:
> Lew Pitcher wrote:
>
>> $# is guaranteed to contain a numeric count of the number of arguments
>> passed into a script. It *cannot* be empty, or contain space delimited
>> values, so bracketing it in doublequotes is redundant.
>
> Double quotes around $# are redundant only if there are no digits in IFS.
>
> That would certainly be true for the case the OP asked about, where the
> $# expansion was in the first command executed in the script. But it
> can't be assumed to be true in general.

IFS is analogous to an important environmental register in a machine
language ABI, such as a global offset pointer register. Code which wants
to manipulate it must save the value, and restore it not only when it
is done, but around calls to any other code.

The onus is on whoever introduces IFS manipulation to do the above,
and in general to debug their shit. We'd never blame a piece of shell
code which does a naked $# expansion for a breakage caused by an altered
IFS; the IFS alteration is to blame.

If you're writing code with unknown callers for general use, you should
cheerfully assume that the normal IFS is in effect, and not do any
obviously unnecessary quoting.

Only code which is specifically a helper routine to some
IFS-manpipulating code (like being part of the same module) has any
reason to defend against the changed IFS.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Re: [ "$#" != "1" ] vs [ $# != 1 ]

<2f500089-9133-4adf-b7f0-6c7672a7f752n@googlegroups.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:622a:38b:b0:2f3:dcce:a7a3 with SMTP id j11-20020a05622a038b00b002f3dccea7a3mr10871858qtx.439.1652591741770;
Sat, 14 May 2022 22:15:41 -0700 (PDT)
X-Received: by 2002:a05:620a:4551:b0:6a0:40d1:44df with SMTP id
u17-20020a05620a455100b006a040d144dfmr8515802qkp.70.1652591741619; Sat, 14
May 2022 22:15:41 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.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: Sat, 14 May 2022 22:15:41 -0700 (PDT)
In-Reply-To: <04v1li-f0i.ln1@ID-313840.user.individual.net>
Injection-Info: google-groups.googlegroups.com; posting-host=139.162.69.194; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 139.162.69.194
References: <dc20a826-9f33-4269-a74f-43baeb0ed7ccn@googlegroups.com>
<slrnt7o4qn.b3l.hymie@nasalinux.net> <4a9a6179-6a26-48a9-bda5-76dd1b5f4761n@googlegroups.com>
<t5j553$d1c$1@dont-email.me> <04v1li-f0i.ln1@ID-313840.user.individual.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <2f500089-9133-4adf-b7f0-6c7672a7f752n@googlegroups.com>
Subject: Re: [ "$#" != "1" ] vs [ $# != 1 ]
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Sun, 15 May 2022 05:15:41 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2004
 by: hongy...@gmail.com - Sun, 15 May 2022 05:15 UTC

On Friday, May 13, 2022 at 8:41:08 PM UTC+8, Geoff Clare wrote:
> Lew Pitcher wrote:
>
> > $# is guaranteed to contain a numeric count of the number of arguments
> > passed into a script. It *cannot* be empty, or contain space delimited
> > values, so bracketing it in doublequotes is redundant.
> Double quotes around $# are redundant only if there are no digits in IFS.

It's empty on my machine (Ubuntu 20.04.3 LTS):

$ echo $IFS

$
> That would certainly be true for the case the OP asked about, where the
> $# expansion was in the first command executed in the script. But it
> can't be assumed to be true in general.
>
> --
> Geoff Clare <net...@gclare.org.uk>

Re: [ "$#" != "1" ] vs [ $# != 1 ]

<vrf18hlpdcdjnqt9dcegqvrovsf2dd75ub@dim53.demon.nl>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
From: k.n...@nospam.demon.nl (Kees Nuyt)
Newsgroups: comp.unix.shell
Subject: Re: [ "$#" != "1" ] vs [ $# != 1 ]
Date: Sun, 15 May 2022 10:57:27 +0200
Reply-To: k.nuyt@nospam.demon.nl
Message-ID: <vrf18hlpdcdjnqt9dcegqvrovsf2dd75ub@dim53.demon.nl>
References: <dc20a826-9f33-4269-a74f-43baeb0ed7ccn@googlegroups.com> <slrnt7o4qn.b3l.hymie@nasalinux.net> <4a9a6179-6a26-48a9-bda5-76dd1b5f4761n@googlegroups.com> <t5j553$d1c$1@dont-email.me> <04v1li-f0i.ln1@ID-313840.user.individual.net> <2f500089-9133-4adf-b7f0-6c7672a7f752n@googlegroups.com>
User-Agent: ForteAgent/7.10.32.1214
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Organization: KPN B.V.
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!npeer.as286.net!npeer-ng0.as286.net!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!abe006.abavia.com!abp003.abavia.com!news.kpn.nl!not-for-mail
Lines: 18
Injection-Date: Sun, 15 May 2022 10:57:28 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 1374
 by: Kees Nuyt - Sun, 15 May 2022 08:57 UTC

On Sat, 14 May 2022 22:15:41 -0700 (PDT), "hongy...@gmail.com"
<hongyi.zhao@gmail.com> wrote:

> It's empty on my machine (Ubuntu 20.04.3 LTS):
>
> $ echo $IFS
>
> $

No, it isn't empty. The characters it contains just do not leave
ink on your canvas.

user@host:~ $ printf '>%s<' "$IFS"|hexdump -C
00000000 3e 20 09 0a 3c |> ..<|
00000005
--
Kees Nuyt

Re: [ "$#" != "1" ] vs [ $# != 1 ]

<2fd12e81-050a-4504-ba21-96b5cb593069n@googlegroups.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:622a:15:b0:2f3:cd8f:2a78 with SMTP id x21-20020a05622a001500b002f3cd8f2a78mr12123066qtw.43.1652621513344;
Sun, 15 May 2022 06:31:53 -0700 (PDT)
X-Received: by 2002:ac8:7d87:0:b0:2f3:edba:a84a with SMTP id
c7-20020ac87d87000000b002f3edbaa84amr12169540qtd.186.1652621513162; Sun, 15
May 2022 06:31:53 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.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: Sun, 15 May 2022 06:31:52 -0700 (PDT)
In-Reply-To: <vrf18hlpdcdjnqt9dcegqvrovsf2dd75ub@dim53.demon.nl>
Injection-Info: google-groups.googlegroups.com; posting-host=165.22.54.254; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 165.22.54.254
References: <dc20a826-9f33-4269-a74f-43baeb0ed7ccn@googlegroups.com>
<slrnt7o4qn.b3l.hymie@nasalinux.net> <4a9a6179-6a26-48a9-bda5-76dd1b5f4761n@googlegroups.com>
<t5j553$d1c$1@dont-email.me> <04v1li-f0i.ln1@ID-313840.user.individual.net>
<2f500089-9133-4adf-b7f0-6c7672a7f752n@googlegroups.com> <vrf18hlpdcdjnqt9dcegqvrovsf2dd75ub@dim53.demon.nl>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <2fd12e81-050a-4504-ba21-96b5cb593069n@googlegroups.com>
Subject: Re: [ "$#" != "1" ] vs [ $# != 1 ]
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Sun, 15 May 2022 13:31:53 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2062
 by: hongy...@gmail.com - Sun, 15 May 2022 13:31 UTC

On Sunday, May 15, 2022 at 4:57:34 PM UTC+8, Kees Nuyt wrote:
> On Sat, 14 May 2022 22:15:41 -0700 (PDT), "hongy...@gmail.com"
> <hongy...@gmail.com> wrote:
>
> > It's empty on my machine (Ubuntu 20.04.3 LTS):
> >
> > $ echo $IFS
> >
> > $
> No, it isn't empty. The characters it contains just do not leave
> ink on your canvas.
>
> user@host:~ $ printf '>%s<' "$IFS"|hexdump -C
> 00000000 3e 20 09 0a 3c |> ..<|
> 00000005

I get the following using od:

$ printf '>%s<' "$IFS"| od -xc --endian=big
0000000 3e20 090a 3c00
> \t \n <
0000005

Why aren't they exactly the same?
HZ

Re: [ "$#" != "1" ] vs [ $# != 1 ]

<t5r0u7$dd3$1@dont-email.me>

 copy mid

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

 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: [ "$#" != "1" ] vs [ $# != 1 ]
Date: Sun, 15 May 2022 15:58:30 +0200
Organization: A noiseless patient Spider
Lines: 43
Message-ID: <t5r0u7$dd3$1@dont-email.me>
References: <dc20a826-9f33-4269-a74f-43baeb0ed7ccn@googlegroups.com>
<slrnt7o4qn.b3l.hymie@nasalinux.net>
<4a9a6179-6a26-48a9-bda5-76dd1b5f4761n@googlegroups.com>
<t5j553$d1c$1@dont-email.me> <04v1li-f0i.ln1@ID-313840.user.individual.net>
<2f500089-9133-4adf-b7f0-6c7672a7f752n@googlegroups.com>
<vrf18hlpdcdjnqt9dcegqvrovsf2dd75ub@dim53.demon.nl>
<2fd12e81-050a-4504-ba21-96b5cb593069n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 15 May 2022 13:58:31 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="20e44c703c0dacf6cdd121c776d49f14";
logging-data="13731"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18jThI9TsQMng9xgDi97rxH"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:ibpeAm/ZHePw0pg8K6SWQGVk/D8=
In-Reply-To: <2fd12e81-050a-4504-ba21-96b5cb593069n@googlegroups.com>
 by: Janis Papanagnou - Sun, 15 May 2022 13:58 UTC

On 15.05.2022 15:31, hongy...@gmail.com wrote:
> On Sunday, May 15, 2022 at 4:57:34 PM UTC+8, Kees Nuyt wrote:
>> On Sat, 14 May 2022 22:15:41 -0700 (PDT), "hongy...@gmail.com"
>> <hongy...@gmail.com> wrote:
>>
>>> It's empty on my machine (Ubuntu 20.04.3 LTS):
>>>
>>> $ echo $IFS
>>>
>>> $
>> No, it isn't empty. The characters it contains just do not leave
>> ink on your canvas.
>>
>> user@host:~ $ printf '>%s<' "$IFS"|hexdump -C
>> 00000000 3e 20 09 0a 3c |> ..<|
>> 00000005
>
> I get the following using od:
>
> $ printf '>%s<' "$IFS"| od -xc --endian=big
> 0000000 3e20 090a 3c00
> > \t \n <
> 0000005
>
> Why aren't they exactly the same?

The output isn't the same because you used a different program.

The IFS value is the same. Of course the unnecessary > and < will
distract you from the IFS dedails in the od/hexdump output. Keep
it simple

$ printf '%s' "$IFS" | od -t x1
0000000 20 09 0a

That's a Blank, a Tab, and a Newline.

Janis

>
> HZ
>

Re: [ "$#" != "1" ] vs [ $# != 1 ]

<704ec164-ae97-48a2-abc3-4c4a05107b82n@googlegroups.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:622a:1007:b0:2f3:ce52:25cb with SMTP id d7-20020a05622a100700b002f3ce5225cbmr14020202qte.575.1652691628461;
Mon, 16 May 2022 02:00:28 -0700 (PDT)
X-Received: by 2002:ad4:4ea9:0:b0:45e:4259:3657 with SMTP id
ed9-20020ad44ea9000000b0045e42593657mr14398021qvb.32.1652691628183; Mon, 16
May 2022 02:00:28 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.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, 16 May 2022 02:00:27 -0700 (PDT)
In-Reply-To: <t5r0u7$dd3$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=165.22.54.254; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 165.22.54.254
References: <dc20a826-9f33-4269-a74f-43baeb0ed7ccn@googlegroups.com>
<slrnt7o4qn.b3l.hymie@nasalinux.net> <4a9a6179-6a26-48a9-bda5-76dd1b5f4761n@googlegroups.com>
<t5j553$d1c$1@dont-email.me> <04v1li-f0i.ln1@ID-313840.user.individual.net>
<2f500089-9133-4adf-b7f0-6c7672a7f752n@googlegroups.com> <vrf18hlpdcdjnqt9dcegqvrovsf2dd75ub@dim53.demon.nl>
<2fd12e81-050a-4504-ba21-96b5cb593069n@googlegroups.com> <t5r0u7$dd3$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <704ec164-ae97-48a2-abc3-4c4a05107b82n@googlegroups.com>
Subject: Re: [ "$#" != "1" ] vs [ $# != 1 ]
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Mon, 16 May 2022 09:00:28 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2875
 by: hongy...@gmail.com - Mon, 16 May 2022 09:00 UTC

On Sunday, May 15, 2022 at 9:58:36 PM UTC+8, Janis Papanagnou wrote:
> On 15.05.2022 15:31, hongy...@gmail.com wrote:
> > On Sunday, May 15, 2022 at 4:57:34 PM UTC+8, Kees Nuyt wrote:
> >> On Sat, 14 May 2022 22:15:41 -0700 (PDT), "hongy...@gmail.com"
> >> <hongy...@gmail.com> wrote:
> >>
> >>> It's empty on my machine (Ubuntu 20.04.3 LTS):
> >>>
> >>> $ echo $IFS
> >>>
> >>> $
> >> No, it isn't empty. The characters it contains just do not leave
> >> ink on your canvas.
> >>
> >> user@host:~ $ printf '>%s<' "$IFS"|hexdump -C
> >> 00000000 3e 20 09 0a 3c |> ..<|
> >> 00000005
> >
> > I get the following using od:
> >
> > $ printf '>%s<' "$IFS"| od -xc --endian=big
> > 0000000 3e20 090a 3c00
> > > \t \n <
> > 0000005
> >
> > Why aren't they exactly the same?
> The output isn't the same because you used a different program.
>
> The IFS value is the same. Of course the unnecessary > and < will
> distract you from the IFS dedails in the od/hexdump output. Keep
> it simple
>
> $ printf '%s' "$IFS" | od -t x1
> 0000000 20 09 0a
>
> That's a Blank, a Tab, and a Newline.

I checked them with the following command:

$ ascii -t 0x20 0x09 0x0a
2/0 32 0x20 0o40 00100000
0/9 9 0x09 0o11 00001001
0/10 10 0x0A 0o12 00001010

How to retrieve the character names at the same time?

HZ

Re: [ "$#" != "1" ] vs [ $# != 1 ]

<1j548hhp5lk50pqg4i27u7jv6k01gp83m1@dim53.demon.nl>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
From: k.n...@nospam.demon.nl (Kees Nuyt)
Newsgroups: comp.unix.shell
Subject: Re: [ "$#" != "1" ] vs [ $# != 1 ]
Date: Mon, 16 May 2022 11:29:35 +0200
Reply-To: k.nuyt@nospam.demon.nl
Message-ID: <1j548hhp5lk50pqg4i27u7jv6k01gp83m1@dim53.demon.nl>
References: <dc20a826-9f33-4269-a74f-43baeb0ed7ccn@googlegroups.com> <slrnt7o4qn.b3l.hymie@nasalinux.net> <4a9a6179-6a26-48a9-bda5-76dd1b5f4761n@googlegroups.com> <t5j553$d1c$1@dont-email.me> <04v1li-f0i.ln1@ID-313840.user.individual.net> <2f500089-9133-4adf-b7f0-6c7672a7f752n@googlegroups.com> <vrf18hlpdcdjnqt9dcegqvrovsf2dd75ub@dim53.demon.nl> <2fd12e81-050a-4504-ba21-96b5cb593069n@googlegroups.com> <t5r0u7$dd3$1@dont-email.me> <704ec164-ae97-48a2-abc3-4c4a05107b82n@googlegroups.com>
User-Agent: ForteAgent/7.10.32.1214
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Organization: KPN B.V.
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe004.abavia.com!abp002.abavia.com!news.kpn.nl!not-for-mail
Lines: 26
Injection-Date: Mon, 16 May 2022 11:29:36 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 1861
 by: Kees Nuyt - Mon, 16 May 2022 09:29 UTC

On Mon, 16 May 2022 02:00:27 -0700 (PDT), "hongy...@gmail.com"
<hongyi.zhao@gmail.com> wrote:

>
> I checked them with the following command:
>
> $ ascii -t 0x20 0x09 0x0a
> 2/0 32 0x20 0o40 00100000
> 0/9 9 0x09 0o11 00001001
> 0/10 10 0x0A 0o12 00001010
>
> How to retrieve the character names at the same time?

1: Explore the options in 'man -s 1 ascii' and try
ascii -a 0xHH ...
plus a bit of awk code

2: You don't have to, because from experience you know
0x20 is space, 0x09 is TAB and 0x0A is linefeed

3: Use the lookup table in 'man -s 7 ascii'

You just failed the quiz.
--
Kees Nuyt

Re: [ "$#" != "1" ] vs [ $# != 1 ]

<3a93c60b-267d-481d-8c91-a6797dcb5cbdn@googlegroups.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:622a:54d:b0:2f3:ce29:234a with SMTP id m13-20020a05622a054d00b002f3ce29234amr17741458qtx.559.1652764941812;
Mon, 16 May 2022 22:22:21 -0700 (PDT)
X-Received: by 2002:a05:622a:354:b0:2f3:ddbf:8198 with SMTP id
r20-20020a05622a035400b002f3ddbf8198mr18205819qtw.417.1652764941622; Mon, 16
May 2022 22:22:21 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.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, 16 May 2022 22:22:21 -0700 (PDT)
In-Reply-To: <1j548hhp5lk50pqg4i27u7jv6k01gp83m1@dim53.demon.nl>
Injection-Info: google-groups.googlegroups.com; posting-host=165.22.54.254; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 165.22.54.254
References: <dc20a826-9f33-4269-a74f-43baeb0ed7ccn@googlegroups.com>
<slrnt7o4qn.b3l.hymie@nasalinux.net> <4a9a6179-6a26-48a9-bda5-76dd1b5f4761n@googlegroups.com>
<t5j553$d1c$1@dont-email.me> <04v1li-f0i.ln1@ID-313840.user.individual.net>
<2f500089-9133-4adf-b7f0-6c7672a7f752n@googlegroups.com> <vrf18hlpdcdjnqt9dcegqvrovsf2dd75ub@dim53.demon.nl>
<2fd12e81-050a-4504-ba21-96b5cb593069n@googlegroups.com> <t5r0u7$dd3$1@dont-email.me>
<704ec164-ae97-48a2-abc3-4c4a05107b82n@googlegroups.com> <1j548hhp5lk50pqg4i27u7jv6k01gp83m1@dim53.demon.nl>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <3a93c60b-267d-481d-8c91-a6797dcb5cbdn@googlegroups.com>
Subject: Re: [ "$#" != "1" ] vs [ $# != 1 ]
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Tue, 17 May 2022 05:22:21 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2513
 by: hongy...@gmail.com - Tue, 17 May 2022 05:22 UTC

On Monday, May 16, 2022 at 5:29:42 PM UTC+8, Kees Nuyt wrote:
> On Mon, 16 May 2022 02:00:27 -0700 (PDT), "hongy...@gmail.com"
> <hongy...@gmail.com> wrote:
>
> >
> > I checked them with the following command:
> >
> > $ ascii -t 0x20 0x09 0x0a
> > 2/0 32 0x20 0o40 00100000
> > 0/9 9 0x09 0o11 00001001
> > 0/10 10 0x0A 0o12 00001010
> >
> > How to retrieve the character names at the same time?
> 1: Explore the options in 'man -s 1 ascii' and try
> ascii -a 0xHH ...
> plus a bit of awk code

$ echo "0x20 0x09 0x0a" | xargs -n1 ascii -a|grep names
Other names: Space, Blank
Other names: Horizontal Tab, \t
Other names: Newline, \n

>
> 2: You don't have to, because from experience you know
> 0x20 is space, 0x09 is TAB and 0x0A is linefeed
>
> 3: Use the lookup table in 'man -s 7 ascii'
>
> You just failed the quiz.
> --
> Kees Nuyt

1
server_pubkey.txt

rocksolid light 0.9.7
clearnet tor