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.
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.
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).
The problem I'm having with `which $PROGRAM` is that it reports exit 0 (successful) even if it's not found.
I'll rephrase my earlier post, as resident jobsworths and unnecessary nitpickers have deranged my OP.
[...]
[I hope but don't expect that the resident Arschloch in chief won't
derange this thread again.]
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.
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'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.
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.
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[…]”
If you are really worried by "fake" perls (and you seem to be) I
don't think you will have much luck.r
The presence of an executable called perl in $PATH does not mean it is
not a "mickey mouse alias".
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).
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 152:42:09 |
| Calls: | 12,091 |
| Calls today: | 4 |
| Files: | 15,000 |
| Messages: | 6,517,648 |