I am trying to write a bash function that behaves similarly to the
where builtin in
where lists all the builtins, aliases, and the absolute paths to executables on the
PATH with a given name, even if they are shadowed, e.g.
tcsh> where tcsh /usr/bin/tcsh /bin/tcsh
As part of this I want to loop over everything in the
$PATH and see if an executable file with the appropriate name exists.
The following bash snippet is intended to loop over a colon-delimited list of paths and print each component followed by a newline, however, it just seems to print the entire contents of
$PATH all on one line
#!/bin/bash while IFS=':' read -r line; do printf "%s\n" "$line" done <<< "$PATH"
As is stands now,
bash where and
./where just print
So, how do I set up my while loop so that the value of the loop variable is each segment of the colon-separated list of paths in turn?