Deutsch   English   Français   Italiano  
<vk4ac6$1v4c6$1@news.xmission.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!news.misty.com!weretis.net!feeder9.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Re: Checking for right # of args in a shell script (Was: a sed
 question)
Date: Fri, 20 Dec 2024 17:43:34 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <vk4ac6$1v4c6$1@news.xmission.com>
References: <874j304vv3.fsf@example.com> <vk40gi$3g9sm$1@dont-email.me> <vk41eb$1uvhe$1@news.xmission.com> <vk43n0$3gtg6$1@dont-email.me>
Injection-Date: Fri, 20 Dec 2024 17:43:34 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
	logging-data="2068870"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
Bytes: 2527
Lines: 38

In article <vk43n0$3gtg6$1@dont-email.me>,
Janis Papanagnou  <janis_papanagnou+ng@hotmail.com> wrote:
....
>> Agreed, in general, but in practice, the need rarely arises.
>
>I certainly disagree on this; if you have 10..19 (or 100..199 etc.)
>arguments the '<' test just doesn't trigger but '-lt' does. I mean,
>why use a wrong operator. If it will only in specific cases produce
>correct results, or if it produced in most cases correct results;
>it's just the wrong thing.

We're not talking about the same thing.

>> 
>> The idiomatic way to do this is just:
>> 
>>     [ $# = 2 ] || usage()
>
>Yes, but I don't use that but prefer (like you) [[...]], an in, say,

[ ] is easier in the simple cases.  But, whatever, either way is fine.

>> Also, when I need to do more complex arg verification, I use bash's [[ ]]
>> mechanism (Yes, I know OP is using /bin/sh, but there is no reason nowadays
>> not to use bash). 
>
>If the OP is on Linux the 'sh' might actually be a Bash. If he's,

I assume Linux unless/until I hear otherwise.  And I tend to also assume
some Debian-based Linux (again, unless/until ...).  In Debian-based
Linuxes, sh is "dash", which is pretty much a minimal
subset/POSIX-compliant version of the shell.  So, [[ ]] isn't available
there.

-- 
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/GodDelusion