Find a file and set path in variable?

Hi Folks -

I was wondering if you could help convert batch code in Linux? For instance, I use the following piece of code in DOS to find a file/executable, and then the FULL path as a variable.

::-- If startMaxl.exe exists, set full path --::
for %%D in (c d e f g h i j k l m n o p q r s t u v w x y z) do if exist %%D: (
    for /f "delims=" %%A in ('dir/b/s %%D:\startMaxl.exe 2^>nul') do (
        SET STARTMAXL=%%A
    )
)

Can someone help me with a similar method for Linux?

Thank you!

Please explain in more detail what this does.

What this does is scan all available drives on the server. I've added c-z to ensure I've captured all possibilities.

Then, when it finds the file it's searching for, it sets the path (including file name) as a variable.

Essentially I need to search the Linux environment for a file, then set that path in a variable.

Thanks!

That's not a sensible concept in UNIX / Linux, or any OS which doesn't have CPM-style drive letters or completely-open file permissions. Attempting this on a UNIX system would be a recipe for disaster, migranes, and disk thrashing.

This may seem like a limitation, but it actually means, if you pick a sensible place for your executable, it won't wander and can be made the same on every machine. Linux also has easier stopgaps, like symbolic links. For that one funny machine where you can't install to /opt/myapplication/myexecutable, you could place a symbolic link or environment to the real location instead.

There were better options in DOS too, to be honest.

You *could* do a

find / -name foo -type f -perm u=x

to find all occurances of a file named foo, but aside from the fact that this will likely take ages (due to the large amount of files). Also be prepared that, unless you run this as root, you will get *plenty* of error messages on stderr, because you don't have permission to dive into every directory.