There's an executable /usr/bin/foo
which I and other scripts use, but it misbehaves a bit so I made a Bash wrapper of the same filename in /usr/local/bin/foo
where I fixed its misbehaviour. My PATH
is /usr/local/bin:/usr/bin
. In the wrapper script, I have to run the original executable by absolute path in order to not get into an infinite loop:
$ cat /usr/local/bin/foo
#/bin/zsh
/usr/bin/foo | grep -v "^INFO" # reduce output
Is there any (Zsh or Bash specific perhaps) straightforward way to execute next foo
in PATH
, that is the foo
that's in PATH
directories that are after the directory from which current foo
was executed, so that I wouldn't have to use absolute path to the original executable?
I could make a function for it in /etc/zshenv
and it's not such a big deal. I'm just wondering if there is anything standard. I don't want to use alias or fix the original executable.
EDIT 1: = $ cat /usr/local/bin/foo #/bin/zsh path=(${path/#%$0:A:h}) foo | grep -v "^INFO" # reduce output
This should empty (but keep) all strings in PATH (${path/...}
) that fully match (#%
) the absolute (:A
) directory (:h
) of the current executable($0
). TBH, I assembled it from StackExchange and don't understand it fully. I hope it's not going to bite me.
EDIT 2:
$ cat /usr/local/bin/foo
#/bin/zsh
path[${path[(i)$0:A:h]}]=() foo | grep -v "^INFO" # reduce output
$path[(i)foo]
finds the index of foo
in the array path
or 1 plus length of the array.
${arr[(i)...]}
only considers exact matches, or am I not understanding the issue? – intelfx Mar 14 '24 at 23:12