Thank you for asking. I would like to create a script which runs Haskell code. The problem is, each user could have the path to runhaskell in a different location. So, using which (or another tool), I would like to get the exact location of the executable.
Unfortunately, I won't know beforehand where the executable location is. So, I am wondering if there is some shell command that allows me to first find the executable path.
You could use locate to find all runhaskells, parse the results for binaries, guess at which to use if there's more than one... Yuck! Oh -- and, by default, locate's database hasn't been built so you'll have to get the user to do that first and wait (and wait, and wait...).
I can think of three ways round this problem. You also distribute the Haskell install, set to put the binary in a known, consistent, place. You tell users that they must install Haskell in a known, consistent, place. Or you have a Global__runhaskellPath in your macro, and on first run you pop a "Please select your Haskell install" dialog, grab the path from that, and use
PATH="$KMVAR_Global__runhaskellPath":$PATH
...at the top of your shell script. The global will persist, so they won't be asked again, but you should probably put some error checking there in case they move stuff around!
I'd try the latter, it seems "friendlier" to your users. It's totally untested, but you should be able to get it (or similar) to work.
Unless your users are on "managed" Macs (via an MDM such as Apple School Manager, Jamf, Munki, etc) I'd jump straight to option 3 and let them tell you where Haskell was installed -- a nicer experience for them and easier for you!
Which means people will have to install Haskell, which (presumably, I've not done it) means they'll also have ~/.ghcup/bin/runhaskell. So I suggest you test for that, use it if it's there, and throw a "Please locate..." prompt if it isn't.