0

For the RTOS I'm writing ( http://www.distortos.org ) I need to run find as part of the build configuration process (from make menuconfig target). For Windows I assume that user has MSYS2 installed, so find.exe is available. The only problem with this particular file is that Windows also has such file in C:/Windows/system32 (supposedly it is something close to grep). So depending on the order of folders in your PATH environment variable you get one or the other if trying to call the file by just the name.

I've found that calling this program as /bin/find from the Makefile or in shell script works both in Windows and on (my) Linux. What is most important - doing it that way always calls find.exe from MSYS2, no matter what is the order of folders in PATH. So I'm wondering - is it OK to call find this way, or maybe it is not portable and I just had luck that it works for me?

Freddie Chopin
  • 8,440
  • 2
  • 28
  • 58
  • 1
    The contents of `/bin` and `/usr/bin` vary, somewhat arbitrarily, from one system to another. Historically `/bin` contained executables that were needed early in the boot process, and `/usr/bin` was often on a separate partition, but that's largely obsolete. Sometimes one is a symlink to the other. – Keith Thompson Apr 18 '16 at 19:03

2 Answers2

1

It would probably be more portable to refer to it as /usr/bin/find. For example, on Fedora /bin is actually a symlink to /usr/bin, so either works:

bash-4.3$ ls -l /bin/find
-rwxr-xr-x. 1 root root 222608 Dec 28 18:26 /bin/find
bash-4.3$ ls -l /usr/bin/find
-rwxr-xr-x. 1 root root 222608 Dec 28 18:26 /usr/bin/find

But on a recent Ubuntu:

root@69ca68fbe5c0:/# ls -l /bin/find
ls: cannot access /bin/find: No such file or directory
root@69ca68fbe5c0:/# ls -l /usr/bin/find
-rwxr-xr-x. 1 root root 229992 Jan  6  2014 /usr/bin/find
larsks
  • 277,717
  • 41
  • 399
  • 399
  • Yes, it works with `/usr/bin/find` too (I actually checked this variant first), but I don't know which location is better... On my Linux `/bin` is also a symlink to `/usr/bin`, the real folder where `find.exe` is in MSYS2 is also reported as `/usr/bin` (by `which find`) and it really is sth like `C:\msys64\usr\bin`. – Freddie Chopin Apr 18 '16 at 18:41
  • 1
    I guess I was suggesting that `/usr/bin/find` is empirically better. – larsks Apr 18 '16 at 19:31
1

I would recommend not hard-coding the path to find and instead instruct Windows users that they must run your script inside the MSYS2 environment. MSYS2 will put its own bin directories near the beginning of the path so that find always gets the MSYS2 version instead of the Microsoft version.

If you hard-code the path to find then you make things be more brittle than they need to be.

David Grayson
  • 84,103
  • 24
  • 152
  • 189