Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Can't tell the difference in operation between PATH_SCRIPT and NO_PATH_SCRIPT



On Thu, Jan 25, 2024, at 11:17 PM, Steve Dondley wrote:
> I guess I never realized that, when it comes to options, there is a 
> difference between running a script directly and passing it as an 
> argument to zsh. 

You're overgeneralizing.  PATH_SCRIPT is defined to only affect the
latter scenario, but you are confused because you have been trying
to apply it to the former scenario.  There is no broader lesson
about options here.

It's like being confused that POSIX_CD doesn't make the jobs(1)
builtin more POSIX-conformant, even though it never claimed to.
It is a category mistake.


> But even still, If I do this:
>
>> echo $PATH
> /usr/bin:./dir
>
>> ls dir
> -rwxr--r-- 1 root root 9 Jan 26 03:26 foo.zsh
>
>> setopt pathscript
>
>> zsh foo.zsh
> zsh: can't open input file: foo.zsh
>
>> unsetopt pathscript
>
>> zsh foo.zsh
> zsh: can't open input file: foo.zsh
>
>
> So I’m still seeing no difference between execution of the script with 
> path script on or off in these cases.

Options are not inherited by child shells created in this manner.
That is why my demonstration used -o and +o.

	% ([[ -o EXTENDED_GLOB ]]; print $?)
	1
	% setopt EXTENDED_GLOB
	% ([[ -o EXTENDED_GLOB ]]; print $?)
	0
	% zsh -c '[[ -o EXTENDED_GLOB ]]; print $?'
	1


> HOWEVER, I discovered if I put this in my .zshrc:
>
> setopt pathscript
>
> and do:
>
>> zsh -i foo.zsh
>
> It works.

Yes, because interactive shells source .zshrc.


> Or, if I do
>
>> setopt pathscript
>
> and then do
>
>> zsh -c foo.zsh
>
> This also works.

No, you are conflating unrelated things again.  With -c, zsh evaluates
the "foo.zsh" argument as a complete script, so it performs a PATH
search as usual.  As I said earlier, PATH_SCRIPT *does not apply* to
''zsh -c''; its status is irrelevant.

	% cat foo.sh
	cat: foo.sh: No such file or directory
	% cat dir/foo.sh
	echo foo
	% PATH=./dir /bin/zsh -o PATH_SCRIPT -c foo.sh 
	foo
	% PATH=./dir /bin/zsh +o PATH_SCRIPT -c foo.sh
	foo


-- 
vq




Messages sorted by: Reverse Date, Date, Thread, Author