tags:

views:

97

answers:

3

Hi all!

I have a sh script (scala compiler). I'm trying to run it from Terminal application: sudo fsc, but it says that the file can't be found. I've set chmod +x, so script should be visible. It's sh script, not bash.

Is it any possible?

UPD: thanks all for the great answers, i really did learn a lot :) to set up Path properly, everyone can see: http://macosx.com/forums/unix-x11/250180-set-path-environment-variable.html thx everyone!

+1  A: 

If the script is in the current directory, you must always prefix its name by "./" which would gave in that case :

sudo ./fsc

Cheers

LePad
wow)) thanks for the answer! but is it possible to do the same for the script that is located in a directory specified in Path?
ifesdjeen
Actually, you don't always have to do this. You have to ensure that 'fsc' is in the path somewhere; but by default, root (whom you sudo to) doesn't have . in the current directory by default. That's actually for a good reason, but it's possible to use sudo to take a different path and use that instead (e.g. sudo ~/bin/scala/fsc)
AlBlue
If the script is in the path, then there's no need to prefix it with anything. Just type the name of the executable script and it should run
LePad
+1  A: 

First, if it's in the local directory and not a directly specified in $PATH, you need to preface it with ./ .

Second, once the script is given execute permissions, if it's still not working, try adding #!/bin/sh or whatever the path to the interpreter is at the top.

phoebus
+1  A: 

Has sudo been configured with the --wth-secure-path option. If so then it will use a secure path and ignore your path setting altogether.

You can find this out by typing sudo -v when you are already root.

If it is configured with secure path then the only way is to put the command into one of the directorys specifed in secure path or to pass the full pathname as the argument to sudo.

Steve Weet
thanks! i did add PATH to env not to paths file. works well!
ifesdjeen