[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: small problem with BASH_SOURCE and PATH
From: |
Greg Wooledge |
Subject: |
Re: small problem with BASH_SOURCE and PATH |
Date: |
Fri, 11 Feb 2022 11:35:56 -0500 |
On Fri, Feb 11, 2022 at 01:57:51PM +0100, Alex fxmbsw7 Ratchev wrote:
> i think this is a bash bug issue
>
> when i type -p randurl.gawk first it works
What does it *say*?
> so i suppose a hash -r should do
Why would removing a hash entry in your interactive shell affect the PATH
used by a script?
> On Thu, Feb 10, 2022 at 11:36 PM Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com>
> wrote:
> >
> > my=/tmp/$SRANDOM ; mkdir -p $my/bin ; cd $my ; printf 'yes | head -3'
> >bin/ye ; printf >script %s\\n '#!/usr/bin/env -S
> > bash' 'PATH=$PATH:${BASH_SOURCE%/*}/bin' 'ye' ; chmod +x * */* ; bash
> script ; ./script
> > script: line 3: ye: command not found
> > y
> > y
> > y
Basically you are assuming that BASH_SOURCE contains something useful
enough to incorporate into the PATH variable during the execution of
a script. And despite getting this error message, you have not even
attempted to look at the values of BASH_SOURCE or PATH to determine
what's actually happened.
unicorn:~$ printf '%s\n' >foo '#!/bin/bash' 'declare -p BASH_SOURCE'; chmod +x
foo
unicorn:~$ ./foo
declare -a BASH_SOURCE=([0]="./foo")
unicorn:~$ bash foo
declare -a BASH_SOURCE=([0]="foo")
As you can see, the value of BASH_SOURCE changes depending on how you
invoke the script.
Consider what happens when you perform ${BASH_SOURCE%/*} on each of these
values. And then what happens when you put the results into PATH.
- small problem with BASH_SOURCE and PATH, Alex fxmbsw7 Ratchev, 2022/02/10
- Re: small problem with BASH_SOURCE and PATH, Alex fxmbsw7 Ratchev, 2022/02/10
- Re: small problem with BASH_SOURCE and PATH, Alex fxmbsw7 Ratchev, 2022/02/10
- Re: small problem with BASH_SOURCE and PATH, Alex fxmbsw7 Ratchev, 2022/02/11
- Re: small problem with BASH_SOURCE and PATH,
Greg Wooledge <=
- Re: small problem with BASH_SOURCE and PATH, Alex fxmbsw7 Ratchev, 2022/02/11
- Re: small problem with BASH_SOURCE and PATH, Alex fxmbsw7 Ratchev, 2022/02/11
- Re: small problem with BASH_SOURCE and PATH, Alex fxmbsw7 Ratchev, 2022/02/11
- Re: small problem with BASH_SOURCE and PATH, Alex fxmbsw7 Ratchev, 2022/02/11
- Re: small problem with BASH_SOURCE and PATH, Alex fxmbsw7 Ratchev, 2022/02/11
- Re: small problem with BASH_SOURCE and PATH, Dennis Williamson, 2022/02/11
- Re: small problem with BASH_SOURCE and PATH, Alex fxmbsw7 Ratchev, 2022/02/11
- Re: small problem with BASH_SOURCE and PATH, Alex fxmbsw7 Ratchev, 2022/02/11
- Re: small problem with BASH_SOURCE and PATH, Greg Wooledge, 2022/02/11
- Re: small problem with BASH_SOURCE and PATH, Alex fxmbsw7 Ratchev, 2022/02/11