gcc12 fault?

Ken Cunningham ken.cunningham.webuse at gmail.com
Fri Jun 2 06:47:35 UTC 2023



> On Jun 1, 2023, at 6:18 PM, Joshua Root <jmr at macports.org> wrote:
> 
> Ken Cunningham wrote:
> 
>> what you see is difficult to explain, unless the PATH changed between the two tests.
>> 
>> if
>> 
>> 'which gcc' gives /opt/local/bin/gcc
>> 
>> then
>> 
>> gcc --version
>> 
>> should give exactly the same as
>> 
>> /opt/local/bin/gcc --version
> 
> Not necessarily. Shells cache command locations, so if 'gcc' was run prior to the creation of /opt/local/bin/gcc, subsequently invocations will continue to run the previously found gcc. Running 'hash -r' or starting a new shell will give you an empty cache and thus set things right.
> 
> The 'which' command doesn't know about the shell's cache state; it only looks at the current PATH. This is why 'type' often helps to understand what's going on in these situations, as Richard hinted.
> 
> - Josh
> 

You have probably already noted that which and type are both built in to the default zsh on Ventura and as far as I can tell from my testing here give identical results in every case. Both correctly predict the binary that will be executed in every case I tried.

What will happen when you add and remove binaries from an upstream PATH folder is a bit difficult to predict accurately. I won't try to summarize the findings only to have someone point out their idea of an exception, but it's fair to say that it's best to open a new shell to get predictable results.

K


More information about the macports-users mailing list