I'm working on a tool for a client which needs to be run as sudo (I found out later that it doesn't work without sudo as I've never worked on a Mac before). I have the binary ready, and I wrote a shell script to call that binary as sudo.
However, the problem is that the shell script isn't able to find the binary, and also it outputs the wrong path with pwd
. The location of the binary isn't fixed and it could be placed anywhere, so I cannot hardcode the path into the shell script.
To elaborate a little on the pwd outputting wrong path: the script was placed in a location whose path is /Volumes/MySSD/MiscFiles/
and the output of pwd
through the shell script was /User/<my client's username>
.
Another important constraint is that my client cannot operate a terminal, so for him when he double clicks on the executable it starts. But I need this to run as sudo otherwise it doesn't work.
So, my question is, is there a way to make it so that when I double click the binary from the file explorer (I think it is called Finder in Mac), it should run as sudo.
Or,is there something wrong I'm doing in my shell script?
this is my shell script
#!/bin/bash
# sudo ./actiontool #actiontool is the binary, and this command didn't work, it gave a no such file or directory error
# echo $(pwd) #this echoed the wrong path
sudo .$(pwd)/actiontool #also didnt work as $(pwd) outputs the wrong path