Monday, May 19, 2025

Odd env behavior

This finds homebrew's bash.

$ env -vvv -P $PATH bash
#env verbosity now at 2
#env verbosity now at 3
#env Searching:    '/Users/beatys/.rbenv/shims:/Users/beatys/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/sbin:/usr/sbin:/Applications/Docker.app/Contents/Resources/bin'
#env  for file:    'bash'
#env   matched:    '/opt/homebrew/bin/bash'
#env executing:    /opt/homebrew/bin/bash
#env    arg[0]=    '/opt/homebrew/bin/bash'

 This does not.

$ env -vvv bash
#env verbosity now at 2
#env verbosity now at 3
#env executing:    bash
#env    arg[0]=    'bash' 

Huh. Looking at the code shows a line

ptr = __DECONST(char *, str); /* XXXX Yes, very dodgy */

I'm not sure that's related, but it is a big type hammer.

#ifndef    __DECONST
#define    __DECONST(type, var)    ((type)(__uintptr_t)(const void *)(var))
#endif