Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Nothing happens.


devel / comp.unix.shell / Ho do I check if a number of programs exist?

SubjectAuthor
* Ho do I check if a number of programs exist?Ottavio Caruso
+* Re: Ho do I check if a number of programs exist?Kenny McCormack
|+* Re: Ho do I check if a number of programs exist?Janis Papanagnou
||`* Re: Ho do I check if a number of programs exist?marrgol
|| `- Re: Ho do I check if a number of programs exist?Janis Papanagnou
|`* Check if a program in an executable, was: Ho do I check if a numberOttavio Caruso
| +- Re: Check if a program in an executable, was: Ho do I check if aOttavio Caruso
| +- Re: Check if a program in an executable, was: Ho do I check if aGrant Taylor
| `* Re: Check if a program in an executable, was: Ho do I check if aGeoff Clare
|  +* Re: Check if a program in an executable, was: Ho do I check if aKenny McCormack
|  |`* Re: Check if a program in an executable, was: Ho do I check if aGrant Taylor
|  | `- Re: Check if a program in an executable, was: Ho do I check if aKenny McCormack
|  `* Re: Check if a program in an executable, was: Ho do I check if aOttavio Caruso
|   `* Re: Check if a program in an executable, was: Ho do I check if aGrant Taylor
|    `- Re: Check if a program in an executable, was: Ho do I check if aGeoff Clare
+- Re: Ho do I check if a number of programs exist?hymie!
+- Re: Ho do I check if a number of programs exist?Janis Papanagnou
+- Re: Ho do I check if a number of programs exist?Lew Pitcher
+* Re: Ho do I check if a number of programs exist?Ben Bacarisse
|`- Re: Ho do I check if a number of programs exist?Grant Taylor
+- Re: Ho do I check if a number of programs exist?Dan Espen
`- Re: Ho do I check if a number of programs exist?Keith Thompson

1
Ho do I check if a number of programs exist?

<t1f5if$vme$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ottavio2...@yahoo.com (Ottavio Caruso)
Newsgroups: comp.unix.shell
Subject: Ho do I check if a number of programs exist?
Date: Wed, 23 Mar 2022 12:58:54 +0000
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <t1f5if$vme$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 23 Mar 2022 12:58:55 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="f8f89055ef450e16e23b6d5c3aed4fd9";
logging-data="32462"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19NtEeTVUPWwZfzhXpPUpYRUf/5JcjApZw="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.0.3
Cancel-Lock: sha1:wPGQm7O1a0g2AyTAH2vHcC/tbFE=
X-No-Archive: yes
Content-Language: en-GB
 by: Ottavio Caruso - Wed, 23 Mar 2022 12:58 UTC

I'll rephrase my earlier post, as resident jobsworths and unnecessary
nitpickers have deranged my OP.

I have a list of applications (say: perl, php, mysql, git) that MUST be
present on the system if the script is expected to run. However, they
must be interpreted and rewritten for their presence in $PATH.

Example:

perl

1) is it in $PATH? Yes, then $PERL becomes `which perl`? No, shout loud
and exit.

2) Wash rinse and repeat for all programs in my list.

The problem I'm having with `which $PROGRAM` is that it reports exit 0
(successful) even if it's not found.

I've checked the above in both /bin/sh (which on my system is a symlink
to dash) and /bin/bash.

"command -v" is really not good for me, because it reports successful if
the application is in an alias and I DO NO WANT THAT.

Arrogance? Maybe, but I need to make sure has a "real" program, not a
mickey mouse alias pointing to a fake perl, php, etc.

[I hope but don't expect that the resident Arschloch in chief won't
derange this thread again.]

Have a wonderful day.

--
Ottavio Caruso

Re: Ho do I check if a number of programs exist?

<t1f6lp$208ji$1@news.xmission.com>

  copy mid

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

  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: Ho do I check if a number of programs exist?
Date: Wed, 23 Mar 2022 13:17:45 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <t1f6lp$208ji$1@news.xmission.com>
References: <t1f5if$vme$1@dont-email.me>
Injection-Date: Wed, 23 Mar 2022 13:17:45 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="2105970"; 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, 23 Mar 2022 13:17 UTC

In article <t1f5if$vme$1@dont-email.me>,
Ottavio Caruso <ottavio2006-usenet2012@yahoo.com> wrote:
>I'll rephrase my earlier post, as resident jobsworths and unnecessary
>nitpickers have deranged my OP.

Nice. I learned a new word today. Good article about it in Wikipedia.
Here's an excerpt:

* Jobsworth:
* A jobsworth is a person who uses the authority of their job in a
* deliberately uncooperative way, or who seemingly delights in acting in an
* obstructive or unhelpful manner. It characterizes one who upholds petty
* rules even at the expense of effectiveness or efficiency.

This is, in fact, a very good description of many/most posters to these
technical newsgroups. They just love whining on and on about and quoting
to each other obscure sh*t from the standards documents that nobody gives a
cr*p about. But they love it.

>I have a list of applications (say: perl, php, mysql, git) that MUST be
>present on the system if the script is expected to run. However, they
>must be interpreted and rewritten for their presence in $PATH.

First, I don't think you need to worry about aliases. Aliases are not
expanded in shell scripts unless you explicitly ask for them to be; there
is an obscure option in bash to turn this on (which you should, of course,
never do). Functions, though, might be an issue (but see below).

I've had best luck with "type" instead of "command" or "which" or anything
else. "type" will return a non-zero exit status if the command is not
found, or a string describing where it was found. You should be able to
parse that output and figure out if it (the location of the command) meets
your requirements.

As long as you don't use the "-a" option, it seems to work the same in dash
and bash (the two shells of interest these days).

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

Re: Ho do I check if a number of programs exist?

<slrnt3md19.4ee.hymie@nasalinux.net>

  copy mid

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

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!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!fx11.iad.POSTED!not-for-mail
Newsgroups: comp.unix.shell
From: hym...@nasalinux.net (hymie!)
Subject: Re: Ho do I check if a number of programs exist?
References: <t1f5if$vme$1@dont-email.me>
Organization: Eric Conspiracy Secret Labs
User-Agent: slrn/pre1.0.4-6 (Linux)
Message-ID: <slrnt3md19.4ee.hymie@nasalinux.net>
Lines: 23
X-Complaints-To: abuse@usenet-news.net
NNTP-Posting-Date: Wed, 23 Mar 2022 14:52:25 UTC
Date: Wed, 23 Mar 2022 14:52:25 GMT
X-Received-Bytes: 1400
 by: hymie! - Wed, 23 Mar 2022 14:52 UTC

In our last episode, the evil Dr. Lacto had captured our hero,
Ottavio Caruso <ottavio2006-usenet2012@yahoo.com>, who said:
> I have a list of applications (say: perl, php, mysql, git) that MUST be
> present on the system if the script is expected to run. However, they
> must be interpreted and rewritten for their presence in $PATH.

> The problem I'm having with `which $PROGRAM` is that it reports exit 0
> (successful) even if it's not found.

Odd. It doesn't for me:

$ which perl
/usr/local/bin/perl
$ echo $?
0 $ which fooz
which: no fooz in (/home/hymie/bin:/usr/local/bin:/usr/bin:/bin:/usr/games:
/usr/lib64/qt/bin:/usr/share/texmf/bin:/usr/local/nmh/bin:
/usr/X11/local/bin:/usr/X11/bin)
$ echo $?
1

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

Re: Ho do I check if a number of programs exist?

<t1fcde$nkp$1@dont-email.me>

  copy mid

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

  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: Ho do I check if a number of programs exist?
Date: Wed, 23 Mar 2022 15:55:41 +0100
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <t1fcde$nkp$1@dont-email.me>
References: <t1f5if$vme$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 23 Mar 2022 14:55:42 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="08198feb9e6c50a0a9f7bba497bf4b5c";
logging-data="24217"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19RJEgose+b+R6cV9rCf3jC"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:5LvE52MX3iSWYrWFFHuXF73XiGg=
In-Reply-To: <t1f5if$vme$1@dont-email.me>
 by: Janis Papanagnou - Wed, 23 Mar 2022 14:55 UTC

On 23.03.2022 13:58, Ottavio Caruso wrote:
> I'll rephrase my earlier post, as resident jobsworths and unnecessary
> nitpickers have deranged my OP.

You seem to still haven't noticed that it was your OP that was deranged.

> [...]
>
> [I hope but don't expect that the resident Arschloch in chief won't
> derange this thread again.]

....bad posting habits and offenses.

Janis

Re: Ho do I check if a number of programs exist?

<t1fcma$q21$1@dont-email.me>

  copy mid

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

  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: Ho do I check if a number of programs exist?
Date: Wed, 23 Mar 2022 16:00:25 +0100
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <t1fcma$q21$1@dont-email.me>
References: <t1f5if$vme$1@dont-email.me> <t1f6lp$208ji$1@news.xmission.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 23 Mar 2022 15:00:26 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="08198feb9e6c50a0a9f7bba497bf4b5c";
logging-data="26689"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19wHmYSo6U2nN3l1PO1O9PU"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:F/cdGTQkEDO0gg42s+m8Ai+CtM0=
In-Reply-To: <t1f6lp$208ji$1@news.xmission.com>
 by: Janis Papanagnou - Wed, 23 Mar 2022 15:00 UTC

On 23.03.2022 14:17, Kenny McCormack wrote:
>
> First, I don't think you need to worry about aliases. Aliases are not
> expanded in shell scripts unless you explicitly ask for them to be;

This is not true.

> there
> is an obscure option in bash to turn this on (which you should, of course,
> never do).

Obviously also not true in bash.

If you have an alias defined it gets expanded.

Janis

Re: Ho do I check if a number of programs exist?

<t1fcqs$3pd$1@dont-email.me>

  copy mid

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

  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: Ho do I check if a number of programs exist?
Date: Wed, 23 Mar 2022 15:02:52 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <t1fcqs$3pd$1@dont-email.me>
References: <t1f5if$vme$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 23 Mar 2022 15:02:52 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="6fa9c201ab5abe7b36647d614586de8a";
logging-data="3885"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/FlKcB43zsQ3hc5+ovxTXvmOcmYOl8LqU="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:8y5/27HPeszmuNhy+WU8TUBHnn8=
 by: Lew Pitcher - Wed, 23 Mar 2022 15:02 UTC

On Wed, 23 Mar 2022 12:58:54 +0000, Ottavio Caruso wrote:

[snip]
> The problem I'm having with `which $PROGRAM` is that it reports exit 0
> (successful) even if it's not found.

Funny, that's not how which(1) is supposed to work.
From the which(1) manpage:
RETURN VALUE
Which returns the number of failed arguments,
or -1 when no `program-name´ was given.

[snip]

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

Re: Ho do I check if a number of programs exist?

<623b3db8$0$485$65785112@news.neostrada.pl>

  copy mid

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

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!news.freedyn.de!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!newsfeed.neostrada.pl!unt-exc-02.news.neostrada.pl!unt-spo-a-02.news.neostrada.pl!news.neostrada.pl.POSTED!not-for-mail
Subject: Re: Ho do I check if a number of programs exist?
Newsgroups: comp.unix.shell
References: <t1f5if$vme$1@dont-email.me> <t1f6lp$208ji$1@news.xmission.com>
<t1fcma$q21$1@dont-email.me>
From: marr...@address.invalid (marrgol)
Date: Wed, 23 Mar 2022 16:33:12 +0100
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
MIME-Version: 1.0
In-Reply-To: <t1fcma$q21$1@dont-email.me>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 8bit
Lines: 22
Message-ID: <623b3db8$0$485$65785112@news.neostrada.pl>
Organization: Telekomunikacja Polska
NNTP-Posting-Host: 176.111.237.144
X-Trace: 1648049592 unt-rea-a-01.news.neostrada.pl 485 176.111.237.144:46908
X-Complaints-To: abuse@news.neostrada.pl
X-Received-Bytes: 1624
 by: marrgol - Wed, 23 Mar 2022 15:33 UTC

On 23/03/2022 at 16.00, Janis Papanagnou wrote:
>> First, I don't think you need to worry about aliases. Aliases are not
>> expanded in shell scripts unless you explicitly ask for them to be;
>
> This is not true.
>
>> there
>> is an obscure option in bash to turn this on (which you should, of course,
>> never do).
>
> Obviously also not true in bash.
>
> If you have an alias defined it gets expanded.

From bash man page:

“Aliases are not expanded when the shell is not interactive,
unless the expand_aliases shell option is set using shopt[…]”

--
mrg

Re: Ho do I check if a number of programs exist?

<87zglghe4n.fsf@bsb.me.uk>

  copy mid

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

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.unix.shell
Subject: Re: Ho do I check if a number of programs exist?
Date: Wed, 23 Mar 2022 15:39:36 +0000
Organization: A noiseless patient Spider
Lines: 49
Message-ID: <87zglghe4n.fsf@bsb.me.uk>
References: <t1f5if$vme$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="e742c43ca1743bcf3f6ce6190600a15e";
logging-data="3458"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX187KzIfivV6dU90DhW6PQVVfpJsNgczNLE="
Cancel-Lock: sha1:dHbIPVkLueHiDaFNAPSwR+9uUlg=
sha1:QgCi3xzbAJIwyAaIf7+x33F/ybw=
X-BSB-Auth: 1.58d998019c2396783f0b.20220323153936GMT.87zglghe4n.fsf@bsb.me.uk
 by: Ben Bacarisse - Wed, 23 Mar 2022 15:39 UTC

Ottavio Caruso <ottavio2006-usenet2012@yahoo.com> writes:

> I have a list of applications (say: perl, php, mysql, git) that MUST
> be present on the system if the script is expected to run. However,
> they must be interpreted and rewritten for their presence in $PATH.
>
> Example:
>
> perl
>
> 1) is it in $PATH? Yes, then $PERL becomes `which perl`? No, shout
> loud and exit.
>
> 2) Wash rinse and repeat for all programs in my list.
>
> The problem I'm having with `which $PROGRAM` is that it reports exit 0
> (successful) even if it's not found.
>
> I've checked the above in both /bin/sh (which on my system is a
> symlink to dash) and /bin/bash.

Hmm... In both bash and dash (a POSIX shell) I get:

$ which perl || echo Eek!
/usr/bin/perl
$ which perlx || echo Eek!
Eek!

> "command -v" is really not good for me, because it reports successful
> if the application is in an alias and I DO NO WANT THAT.
>
> Arrogance? Maybe, but I need to make sure has a "real" program, not a
> mickey mouse alias pointing to a fake perl, php, etc.

If you are really worried by "fake" perls (and you seem to be) I don't
think you will have much luck. The presence of an executable called
perl in $PATH does not mean it is not a "mickey mouse alias". Not only
might it exec("/use/bin/awk"), it might even be a dangerous perl-like
program (so you can't check just by running some simple perl). To be
sure (or at least a bit more sure) you could checksum the binary you
find, but that's going to be way more complicated.

As the risk of being called a jobsworthy, I'll ask if an executable
called /usr/bin/perl that executes /usr/local/bin/perl is something you
worry about? It's not clear how far the notion of a mickey mouse alias
extends.

--
Ben.

Re: Ho do I check if a number of programs exist?

<t1ffnr$i40$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: dan1es...@gmail.com (Dan Espen)
Newsgroups: comp.unix.shell
Subject: Re: Ho do I check if a number of programs exist?
Date: Wed, 23 Mar 2022 11:52:26 -0400
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <t1ffnr$i40$1@dont-email.me>
References: <t1f5if$vme$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="6112a0be819832511c0c0d27042b50af";
logging-data="18560"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/4Z8+GzG9rQ90BbZluLv0cr0g/Cft1OU0="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:ZYt9QILAgpfQJTsQ1HHAvJ16dKo=
 by: Dan Espen - Wed, 23 Mar 2022 15:52 UTC

Ottavio Caruso <ottavio2006-usenet2012@yahoo.com> writes:

> I have a list of applications (say: perl, php, mysql, git) that MUST
> be present on the system if the script is expected to run. However,
> they must be interpreted and rewritten for their presence in $PATH.

What you describe is commonly done by an installation tool.
If you take a look at autoconf, you can see how that's commonly done.
It's not always done by looking for the executable.

I don't see much point by doing the checks every time the tool is run
unless you are in some unusual environment. How much more useful is
your error message going to be vs. the error the script will generate
when it tries to run the missing program?

--
Dan Espen

Re: Ho do I check if a number of programs exist?

<877d8k3b2n.fsf@nosuchdomain.example.com>

  copy mid

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

  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: Ho do I check if a number of programs exist?
Date: Wed, 23 Mar 2022 09:09:20 -0700
Organization: None to speak of
Lines: 34
Message-ID: <877d8k3b2n.fsf@nosuchdomain.example.com>
References: <t1f5if$vme$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="87f137ede5f0d05ab425809d835c27b7";
logging-data="22959"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19XRRN93THHoMKzAVMgNRSt"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:Wpjh4MLv0/3l3ewySBAFG7f8RHw=
sha1:Pcs7jkZihHHFKIhzld2G+deUKvI=
 by: Keith Thompson - Wed, 23 Mar 2022 16:09 UTC

Ottavio Caruso <ottavio2006-usenet2012@yahoo.com> writes:
> I'll rephrase my earlier post, as resident jobsworths and unnecessary
> nitpickers have deranged my OP.
>
> I have a list of applications (say: perl, php, mysql, git) that MUST
> be present on the system if the script is expected to run. However,
> they must be interpreted and rewritten for their presence in $PATH.
>
> Example:
>
> perl
>
> 1) is it in $PATH? Yes, then $PERL becomes `which perl`? No, shout
> loud and exit.
>
> 2) Wash rinse and repeat for all programs in my list.
>
> The problem I'm having with `which $PROGRAM` is that it reports exit 0
> (successful) even if it's not found.
>
> I've checked the above in both /bin/sh (which on my system is a
> symlink to dash) and /bin/bash.
>
> "command -v" is really not good for me, because it reports successful
> if the application is in an alias and I DO NO WANT THAT.
[...]

Why are you using the external "which" command rather than the builtin
"type"?

--
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: Ho do I check if a number of programs exist?

<t1fjl3$nau$1@dont-email.me>

  copy mid

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

  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: Ho do I check if a number of programs exist?
Date: Wed, 23 Mar 2022 17:59:15 +0100
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <t1fjl3$nau$1@dont-email.me>
References: <t1f5if$vme$1@dont-email.me> <t1f6lp$208ji$1@news.xmission.com>
<t1fcma$q21$1@dont-email.me> <623b3db8$0$485$65785112@news.neostrada.pl>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 23 Mar 2022 16:59:15 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="08198feb9e6c50a0a9f7bba497bf4b5c";
logging-data="23902"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/HW20MwJPdjALtQzZ1VTMB"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:uYxzo9GeHturX8jyjQDmIbPhMas=
In-Reply-To: <623b3db8$0$485$65785112@news.neostrada.pl>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Wed, 23 Mar 2022 16:59 UTC

On 23.03.2022 16:33, marrgol wrote:
> On 23/03/2022 at 16.00, Janis Papanagnou wrote:
>>> First, I don't think you need to worry about aliases. Aliases are not
>>> expanded in shell scripts unless you explicitly ask for them to be;
>>
>> This is not true.
>>
>>> there
>>> is an obscure option in bash to turn this on (which you should, of
>>> course,
>>> never do).
>>
>> Obviously also not true in bash.
>>
>> If you have an alias defined it gets expanded.
>
> From bash man page:
>
> “Aliases are not expanded when the shell is not interactive,
> unless the expand_aliases shell option is set using shopt[…]”

Right for case:
IF bash AND IF non-interactive => non-expanded

Wrong for cases:
IF bash AND IF interactive => expanded
IF ksh (generally) => expanded
IF zsh (generally) => expanded

Janis

Re: Ho do I check if a number of programs exist?

<t1g0on$2fq$1@tncsrv09.home.tnetconsulting.net>

  copy mid

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

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!tncsrv06.tnetconsulting.net!tncsrv09.home.tnetconsulting.net!.POSTED.alpha.home.tnetconsulting.net!not-for-mail
From: gtay...@tnetconsulting.net (Grant Taylor)
Newsgroups: comp.unix.shell
Subject: Re: Ho do I check if a number of programs exist?
Date: Wed, 23 Mar 2022 14:43:30 -0600
Organization: TNet Consulting
Message-ID: <t1g0on$2fq$1@tncsrv09.home.tnetconsulting.net>
References: <t1f5if$vme$1@dont-email.me> <87zglghe4n.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 23 Mar 2022 20:43:03 -0000 (UTC)
Injection-Info: tncsrv09.home.tnetconsulting.net; posting-host="alpha.home.tnetconsulting.net:198.18.18.251";
logging-data="2554"; mail-complaints-to="newsmaster@tnetconsulting.net"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
In-Reply-To: <87zglghe4n.fsf@bsb.me.uk>
Content-Language: en-US
 by: Grant Taylor - Wed, 23 Mar 2022 20:43 UTC

On 3/23/22 9:39 AM, Ben Bacarisse wrote:
> If you are really worried by "fake" perls (and you seem to be) I
> don't think you will have much luck.r

Agreed.

I think about the best that can /easily/ and / or /quickly/ be done is
to see if the path is that of a known non-functional version.

The next best thing that I can think of is to check the version reported
by the program to see if it's at least the minimum requisite version.
-- Seeing as how this test is program specific, it's trivial to have
proper syntax for said program to check it's version.

> The presence of an executable called perl in $PATH does not mean it is
> not a "mickey mouse alias".

The traditional Sys V vs UCB commands installed on the same system but
in different directories comes to mind. Both are provided by the
vendor. Which one is used is dependent on the user's PATH.

This is why I've been asking for more information on how to identify the
proper version in the hopes to differentiate it from a so called Mickey
Mouse version.

--
Grant. . . .
unix || die

Check if a program in an executable, was: Ho do I check if a number of programs exist?

<t1i3nf$r90$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ottavio2...@yahoo.com (Ottavio Caruso)
Newsgroups: comp.unix.shell
Subject: Check if a program in an executable, was: Ho do I check if a number
of programs exist?
Date: Thu, 24 Mar 2022 15:45:50 +0000
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <t1i3nf$r90$1@dont-email.me>
References: <t1f5if$vme$1@dont-email.me> <t1f6lp$208ji$1@news.xmission.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 24 Mar 2022 15:45:51 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="41309657e0661103266f5b7b8342eaec";
logging-data="27936"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+GhlQSr8NOWDyF1iwJ9ZUn+TO0zhFOBgs="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.0.3
Cancel-Lock: sha1:n0bd1aVWLIuSB+ChtR6qXB9cLOA=
X-No-Archive: yes
In-Reply-To: <t1f6lp$208ji$1@news.xmission.com>
Content-Language: en-GB
 by: Ottavio Caruso - Thu, 24 Mar 2022 15:45 UTC

On 23/03/2022 13:17, Kenny McCormack wrote:
> I've had best luck with "type" instead of "command" or "which" or anything
> else. "type" will return a non-zero exit status if the command is not
> found, or a string describing where it was found. You should be able to
> parse that output and figure out if it (the location of the command) meets
> your requirements.
>
> As long as you don't use the "-a" option, it seems to work the same in dash
> and bash (the two shells of interest these days).

Thanks it makes sense, but I'd like to rephrase my question (and sorry
that I didn't do my homework. I genuinely don't have a stable Internet
connection and I have to rely to the *couch* public library or what
remains of it):

How can I check that a number of programs are installed _and_ point to a
true executable rather than a shell script or similar?

Now, I prevent one of the possible objections: Debian makes great use of
alternatives[1], therefore most programs do point to a shell script or a
link rather than an executable. I'll have to make an explicit exception
for Debian/Ubuntu and similar.

[1] https://wiki.debian.org/DebianAlternatives

--
Ottavio Caruso

Re: Check if a program in an executable, was: Ho do I check if a number of programs exist?

<t1i3uo$r90$2@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ottavio2...@yahoo.com (Ottavio Caruso)
Newsgroups: comp.unix.shell
Subject: Re: Check if a program in an executable, was: Ho do I check if a
number of programs exist?
Date: Thu, 24 Mar 2022 15:49:44 +0000
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <t1i3uo$r90$2@dont-email.me>
References: <t1f5if$vme$1@dont-email.me> <t1f6lp$208ji$1@news.xmission.com>
<t1i3nf$r90$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 24 Mar 2022 15:49:44 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="41309657e0661103266f5b7b8342eaec";
logging-data="27936"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/pcY0+oTMZnpHVdNI38sDZ1PhEAyViD8Q="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.0.3
Cancel-Lock: sha1:DlE15b3YxyqDRXR+EDNH6wUSAXs=
X-No-Archive: yes
In-Reply-To: <t1i3nf$r90$1@dont-email.me>
Content-Language: en-GB
 by: Ottavio Caruso - Thu, 24 Mar 2022 15:49 UTC

On 24/03/2022 15:45, Ottavio Caruso wrote:
> I genuinely don't have a stable Internet connection and I have to rely
> to the *couch* public library or what remains of it):

And the typos are an evidence of this, plus lack of sleep.

s/a program in/a program is
s/ho/how
s/couch/cough

and possibly more.

--
Ottavio Caruso

Re: Check if a program in an executable, was: Ho do I check if a number of programs exist?

<t1ij2s$pb2$1@tncsrv09.home.tnetconsulting.net>

  copy mid

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

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!tncsrv06.tnetconsulting.net!tncsrv09.home.tnetconsulting.net!.POSTED.alpha.home.tnetconsulting.net!not-for-mail
From: gtay...@tnetconsulting.net (Grant Taylor)
Newsgroups: comp.unix.shell
Subject: Re: Check if a program in an executable, was: Ho do I check if a
number of programs exist?
Date: Thu, 24 Mar 2022 14:08:24 -0600
Organization: TNet Consulting
Message-ID: <t1ij2s$pb2$1@tncsrv09.home.tnetconsulting.net>
References: <t1f5if$vme$1@dont-email.me> <t1f6lp$208ji$1@news.xmission.com>
<t1i3nf$r90$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 24 Mar 2022 20:07:56 -0000 (UTC)
Injection-Info: tncsrv09.home.tnetconsulting.net; posting-host="alpha.home.tnetconsulting.net:198.18.18.251";
logging-data="25954"; mail-complaints-to="newsmaster@tnetconsulting.net"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
In-Reply-To: <t1i3nf$r90$1@dont-email.me>
Content-Language: en-US
 by: Grant Taylor - Thu, 24 Mar 2022 20:08 UTC

On 3/24/22 9:45 AM, Ottavio Caruso wrote:
> Thanks it makes sense, but I'd like to rephrase my question (and
> sorry that I didn't do my homework. I genuinely don't have a stable
> Internet connection and I have to rely to the *couch* public library
> or what remains of it):

IMHO there's no need to apologize. I consider the nature of discussions
to involve learning and / or corrections and / or clarifications.

> How can I check that a number of programs are installed _and_ point
> to a true executable rather than a shell script or similar?

It sounds like you mean "binary" as opposed to "executable". I consider
scripts to be executables.

I'd suggest focusing on a (repeatable) process to check an individual
file to determine if it meets your standards or not.

Once you have that process you would loop across the list of files to
see if each file.

> Now, I prevent one of the possible objections: Debian makes great
> use of alternatives[1], therefore most programs do point to a shell
> script or a link rather than an executable. I'll have to make an
> explicit exception for Debian/Ubuntu and similar.

I know that some programs actually use sym-links to provide varies ways
to invoke the compiled binary. BusyBox is an example of such a
quintessential binary wherein many different command names link to one
binary and the binary behaves differently based on the invoking name.

Another example is contemporary Solaris systems making /bin itself a
sym-link to /usr/bin. So, what would you consider /bin/ls which is
(indirectly) a sym-link to /usr/bin/ls.

Aside: What if hard links are used in lieu of sym-links?

Without a clear definition of what a proper executable (binary?) is,
it's near impossible to derive a test that takes into account many
different things that Unix has done over the years. Especially if you
want to account for more esoteric things like over-mounting, hard links,
LD_PRELOAD interceptions, etc.

--
Grant. . . .
unix || die

Re: Check if a program in an executable, was: Ho do I check if a number of programs exist?

<ubt0hi-e6r.ln1@ID-313840.user.individual.net>

  copy mid

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

  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: Check if a program in an executable, was: Ho do I check if a
number of programs exist?
Date: Fri, 25 Mar 2022 13:40:46 +0000
Lines: 36
Message-ID: <ubt0hi-e6r.ln1@ID-313840.user.individual.net>
References: <t1f5if$vme$1@dont-email.me> <t1f6lp$208ji$1@news.xmission.com>
<t1i3nf$r90$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 I1AMwh2KVEqZyzBppbeIqwJAM5b7pauRvxNUUx3JRcJ0W2unPW
X-Orig-Path: ID-313840.user.individual.net!not-for-mail
Cancel-Lock: sha1:IfHH/CwTavqKdPF+Ad9yQjE7lPw=
User-Agent: Pan/0.145 (Duplicitous mercenary valetism; d7e168a
git.gnome.org/pan2)
 by: Geoff Clare - Fri, 25 Mar 2022 13:40 UTC

Ottavio Caruso wrote:

> How can I check that a number of programs are installed _and_ point to a
> true executable rather than a shell script or similar?

Shell scripts *are* true executables. For example:

$ type google-chrome
google-chrome is /bin/google-chrome
$ file /bin/google-chrome
/bin/google-chrome: Bourne-Again shell script, ASCII text executable

This is the genuine google-chrome browser, as provided by Google in
a .deb package. Of course, the script ends up executing a binary,
but that binary is not intended to be executed directly by users.

If you want to distinguish original shell scripts from ones a user
has created, you could perhaps use command -p -v to do a PATH search
of only the "system" PATH instead of the user's PATH. However, there
can be legitimate reasons for users to create wrapper scripts. For
example, I have:

$ cat ~/bin/mutt
#! /bin/sh

# this prevents blinking
case $TERM in
xterm) TERM=xterm-256color ;;
esac

exec /bin/mutt "$@"

You do your users a disservice if you prevent them doing such things.

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

Re: Check if a program in an executable, was: Ho do I check if a number of programs exist?

<t1kukk$23eg1$1@news.xmission.com>

  copy mid

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

  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: Check if a program in an executable, was: Ho do I check if a
number of programs exist?
Date: Fri, 25 Mar 2022 17:37:25 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <t1kukk$23eg1$1@news.xmission.com>
References: <t1f5if$vme$1@dont-email.me> <t1f6lp$208ji$1@news.xmission.com> <t1i3nf$r90$1@dont-email.me> <ubt0hi-e6r.ln1@ID-313840.user.individual.net>
Injection-Date: Fri, 25 Mar 2022 17:37:25 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="2210305"; 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 - Fri, 25 Mar 2022 17:37 UTC

In article <ubt0hi-e6r.ln1@ID-313840.user.individual.net>,
Geoff Clare <netnews@gclare.org.uk> wrote:
>Ottavio Caruso wrote:
>
>> How can I check that a number of programs are installed _and_ point to a
>> true executable rather than a shell script or similar?
>
>Shell scripts *are* true executables. For example:

Indeed. It is really hard to figure out what OP's real problem is.

It would be useful if he would give us a good example (i.e., description
of) the problem/error case he is worried about. i.e., what is the failure?

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

Re: Check if a program in an executable, was: Ho do I check if a number of programs exist?

<t1l2eh$kvr$1@tncsrv09.home.tnetconsulting.net>

  copy mid

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

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!tncsrv06.tnetconsulting.net!tncsrv09.home.tnetconsulting.net!.POSTED.alpha.home.tnetconsulting.net!not-for-mail
From: gtay...@tnetconsulting.net (Grant Taylor)
Newsgroups: comp.unix.shell
Subject: Re: Check if a program in an executable, was: Ho do I check if a
number of programs exist?
Date: Fri, 25 Mar 2022 12:42:53 -0600
Organization: TNet Consulting
Message-ID: <t1l2eh$kvr$1@tncsrv09.home.tnetconsulting.net>
References: <t1f5if$vme$1@dont-email.me> <t1f6lp$208ji$1@news.xmission.com>
<t1i3nf$r90$1@dont-email.me> <ubt0hi-e6r.ln1@ID-313840.user.individual.net>
<t1kukk$23eg1$1@news.xmission.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 25 Mar 2022 18:42:25 -0000 (UTC)
Injection-Info: tncsrv09.home.tnetconsulting.net; posting-host="alpha.home.tnetconsulting.net:198.18.18.251";
logging-data="21499"; mail-complaints-to="newsmaster@tnetconsulting.net"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
In-Reply-To: <t1kukk$23eg1$1@news.xmission.com>
Content-Language: en-US
 by: Grant Taylor - Fri, 25 Mar 2022 18:42 UTC

On 3/25/22 11:37 AM, Kenny McCormack wrote:
> It would be useful if he would give us a good example (i.e.,
> description of) the problem/error case he is worried about.

+10

--
Grant. . . .
unix || die

Re: Check if a program in an executable, was: Ho do I check if a number of programs exist?

<t1l2tc$23h6i$1@news.xmission.com>

  copy mid

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

  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: Check if a program in an executable, was: Ho do I check if a
number of programs exist?
Date: Fri, 25 Mar 2022 18:50:20 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <t1l2tc$23h6i$1@news.xmission.com>
References: <t1f5if$vme$1@dont-email.me> <ubt0hi-e6r.ln1@ID-313840.user.individual.net> <t1kukk$23eg1$1@news.xmission.com> <t1l2eh$kvr$1@tncsrv09.home.tnetconsulting.net>
Injection-Date: Fri, 25 Mar 2022 18:50:20 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="2213074"; 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 - Fri, 25 Mar 2022 18:50 UTC

In article <t1l2eh$kvr$1@tncsrv09.home.tnetconsulting.net>,
Grant Taylor <gtaylor@tnetconsulting.net> wrote:
>On 3/25/22 11:37 AM, Kenny McCormack wrote:
>> It would be useful if he would give us a good example (i.e.,
>> description of) the problem/error case he is worried about.
>
>+10

Thank you.

--
Life's big questions are big in the sense that they are momentous. However, contrary to
appearances, they are not big in the sense of being unanswerable. It is only that the answers
are generally unpalatable. There is no great mystery, but there is plenty of horror.
(https://en.wikiquote.org/wiki/David_Benatar)

Re: Check if a program in an executable, was: Ho do I check if a number of programs exist?

<t1unjh$epr$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ottavio2...@yahoo.com (Ottavio Caruso)
Newsgroups: comp.unix.shell
Subject: Re: Check if a program in an executable, was: Ho do I check if a
number of programs exist?
Date: Tue, 29 Mar 2022 11:38:40 +0100
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <t1unjh$epr$1@dont-email.me>
References: <t1f5if$vme$1@dont-email.me> <t1f6lp$208ji$1@news.xmission.com>
<t1i3nf$r90$1@dont-email.me> <ubt0hi-e6r.ln1@ID-313840.user.individual.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 29 Mar 2022 10:38:41 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="09c649074d04006d6c137c8162539365";
logging-data="15163"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18fTnNa8UTl4PSDGpkJodWV0MsPY66NIqE="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.0.3
Cancel-Lock: sha1:5upPxJkmFrsJ3o4ZnW0+Smh4ZZY=
X-No-Archive: yes
In-Reply-To: <ubt0hi-e6r.ln1@ID-313840.user.individual.net>
Content-Language: en-GB
 by: Ottavio Caruso - Tue, 29 Mar 2022 10:38 UTC

On 25/03/2022 17:37, Kenny McCormack wrote:
> It would be useful if he would give us a good example (i.e., description
> of) the problem/error case he is worried about. i.e., what is the
failure?

See below.

On 25/03/2022 13:40, Geoff Clare wrote:
> If you want to distinguish original shell scripts from ones a user
> has created, you could perhaps use command -p -v to do a PATH search
> of only the "system" PATH instead of the user's PATH.

Thanks. `command -p` is exactly what I was looking for

$ (command -v ffmpeg 2>/dev/null)&& echo success || echo failure
/home/oc/opt/bin/ffmpeg
success

$ (command -p ffmpeg 2>/dev/null)&& echo success || echo failure
failure

Pedantic question: Is `command -p` implemented consistently across all
/bin/sh clones? Can the user hack the " PATH that guarantees to find all
the standard utilities"?

--
Ottavio Caruso

Re: Check if a program in an executable, was: Ho do I check if a number of programs exist?

<t1vrcu$h6s$1@tncsrv09.home.tnetconsulting.net>

  copy mid

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

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!tncsrv06.tnetconsulting.net!tncsrv09.home.tnetconsulting.net!.POSTED.alpha.home.tnetconsulting.net!not-for-mail
From: gtay...@tnetconsulting.net (Grant Taylor)
Newsgroups: comp.unix.shell
Subject: Re: Check if a program in an executable, was: Ho do I check if a
number of programs exist?
Date: Tue, 29 Mar 2022 14:50:04 -0600
Organization: TNet Consulting
Message-ID: <t1vrcu$h6s$1@tncsrv09.home.tnetconsulting.net>
References: <t1f5if$vme$1@dont-email.me> <t1f6lp$208ji$1@news.xmission.com>
<t1i3nf$r90$1@dont-email.me> <ubt0hi-e6r.ln1@ID-313840.user.individual.net>
<t1unjh$epr$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 29 Mar 2022 20:49:34 -0000 (UTC)
Injection-Info: tncsrv09.home.tnetconsulting.net; posting-host="alpha.home.tnetconsulting.net:198.18.18.251";
logging-data="17628"; mail-complaints-to="newsmaster@tnetconsulting.net"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
In-Reply-To: <t1unjh$epr$1@dont-email.me>
Content-Language: en-US
 by: Grant Taylor - Tue, 29 Mar 2022 20:50 UTC

On 3/29/22 4:38 AM, Ottavio Caruso wrote:
> See below.

I don't see an answer to what the problem / error case is.

The example is a couple of options related to ffmpeg. But nothing about
why /home/oc/opt/bin/ffmpeg vs /usr/local/bin/ffmpeg is a problem.

> Thanks. `command -p` is exactly what I was looking for

My read of Zsh's man page for `command -p` makes me believe that
(symbolic) links will be followed. And I thought that you had indicated
that you wanted to exclude (symbolic) links too.

> Pedantic question: Is `command -p` implemented consistently across all
> /bin/sh clones?

I don't know.

> Can the user hack the PATH that guarantees to find all the standard
> utilities?

I don't know if the /user/ can or not. I strongly suspect that an
administrator can change the system / default path to be anything they want.

Also, what is the "default path" and how does it differ from the
(user's) "non-default path"? -- What if a system administrator puts a
symbolic link in a directory that's earlier in the default path? E.g.

PATH=/bin:/usr/bin:/usr/local/bin

/bin/ffmpeg -> /home/oc/opt/bin/ffmpeg

I strongly suspect that even `command -p ffmpeg` would produce unwanted
results.

If you don't like the sym-link, try a hard link on a common file system.
Or how about a wrapper script. Or how about a compiled binary that
shells out to /home/oc/opt/bin/ffmpeg.

We still don't have any working understanding of what the problem /
error case is that you are worried about.

--
Grant. . . .
unix || die

Re: Check if a program in an executable, was: Ho do I check if a number of programs exist?

<65vdhi-1dj.ln1@ID-313840.user.individual.net>

  copy mid

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

  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: Check if a program in an executable, was: Ho do I check if a
number of programs exist?
Date: Wed, 30 Mar 2022 13:31:02 +0100
Lines: 34
Message-ID: <65vdhi-1dj.ln1@ID-313840.user.individual.net>
References: <t1f5if$vme$1@dont-email.me> <t1f6lp$208ji$1@news.xmission.com>
<t1i3nf$r90$1@dont-email.me> <ubt0hi-e6r.ln1@ID-313840.user.individual.net>
<t1unjh$epr$1@dont-email.me> <t1vrcu$h6s$1@tncsrv09.home.tnetconsulting.net>
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 vIrAEleG22+6n5DgxLQXVAGbtDwGyb12n9jENjuOnlHPzYWrYW
X-Orig-Path: ID-313840.user.individual.net!not-for-mail
Cancel-Lock: sha1:jvGkhyRGiWMV7Jy5BSuLk3hQhek=
User-Agent: Pan/0.145 (Duplicitous mercenary valetism; d7e168a
git.gnome.org/pan2)
 by: Geoff Clare - Wed, 30 Mar 2022 12:31 UTC

Grant Taylor wrote:

> On 3/29/22 4:38 AM, Ottavio Caruso wrote:
>
>> Thanks. `command -p` is exactly what I was looking for
>
> My read of Zsh's man page for `command -p` makes me believe that
> (symbolic) links will be followed. And I thought that you had indicated
> that you wanted to exclude (symbolic) links too.

I suggested command -v -p because I suspected that what Ottavio really
wanted was to distinguish "original" (system-supplied) executables from
user-supplied ones, rather than taking any notice of what type of
executable they are. I gave an example of an original shell script
(google-chrome), but the same would apply to symbolic links as well.

>
>> Pedantic question: Is `command -p` implemented consistently across all
>> /bin/sh clones?

POSIX requires that it searches a default PATH "that is guaranteed to
find all of the standard utilities", instead of the PATH value from
the environment. The contents of the default PATH could be chosen by
the shell author, or they could leave it to the C library by using
confstr() with _CS_PATH to obtain a suitable PATH.

>> Can the user hack the PATH that guarantees to find all the standard
>> utilities?

No, it's built into the shell. (The "command" utility is necessarily
implemented as a shell built-in.)

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

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor