I tried using sed
to convert PATH
paths as an input to find
:
User.Name@Machine-Name ~
$ echo $PATH | sed -e 's/:/\n/g' \
| sed -n -e 's=.*="&"=' -e '2,5p'
"/bin"
"/usr/local/bin"
"/usr/bin"
"/c/Program Files/Eclipse Adoptium/jdk-8.0.392.8-hotspot/bin"
The paths are quoted to protect spaces. Unfortunately, they aren't recognized properly when submitted to find
:
User.Name@Machine-Name ~
$ find \
$(echo $PATH | sed -e 's/:/\n/g' | sed -n -e 's=.*="&"=' -e '2,5p') \
-iname '*libc*'
find: ‘"/bin"’: No such file or directory
find: ‘"/usr/local/bin"’: No such file or directory
find: ‘"/usr/bin"’: No such file or directory
find: ‘"/c/Program’: No such file or directory
find: ‘Files/Eclipse’: No such file or directory
find: ‘Adoptium/jdk-8.0.392.8-hotspot/bin"’: No such file or directory
In fact, the spaces aren't protected and are interpretted as argument delimiters.
On the other hand, if I simply type in a quoted path, it works fine:
User.Name@Machine-Name ~
$ find "/bin" -iname '*libc*' # Finds nothing, but no syntax error
User.Name@Machine-Name ~
How can I understand this and how can I efficiently convert PATH
paths into arguments (say, for find
)?