Running a script as sudo wihout terminal

The full path of the shell script including its name is in $0. You can extract the path by using ${0%/*}.

This doesn't solve other issues though:

  • Double-clicking the script will open Terminal which might confuse the user
  • sudo will only work as expected if the user is an Administrator (or if you changed /etc/sudoers but I assume you didn't)
  • They still need to enter their password in the Terminal window.

PS: The probably better way to approach this might be handling any access right issues from within the application.