% sudo ./my_script.sh var1
sudo: ./my_script.sh: command not found
This message indicates that either the file ./my_script.sh
doesn't exist, or its loader doesn't exist. For a script, the loader is the executable mentioned in the shebang line.
Check that /usr/local/bin/zsh
exists and that it isn't a broken symbolic link.
Check that the file really does contain #!/usr/local/bin/zsh
as its first line and not, say #!/usr/local/bin/zsh
with some whitespace or otherwise invisible characters after it or in the middle. Note in particular that a carriage return is one of the invisible characters that would break things. You would end up with a CR if you created (or perhaps if you edited) the script under Windows; if you edit scripts under Windows, make sure they're saved with line endings set to “LF” or “Unix” or “Linux” or whatever your editor calls it..
% sudo my_script.sh var1
sudo: my_script.sh: command not found
This one doesn't work for a simple reason: myscript.sh
is not in the command search path.
% sudo source my_script.sh var1
sudo: source: command not found
This one doesn't work for a simple reason: source
is a shell builtin, it isn't an executable. (It would make no sense as an executable since its purpose is to execute some shell code in the current shell — only a shell can do that.)
Which shell you're currently running is irrelevant for all three commands.
x
permission for others, but not for the owner or group. – Jun 14 '17 at 02:56noexec
? – steeldriver Jun 14 '17 at 03:18sudo -E ./my_script.sh arg1
? A good practice when writing scripts that use programs and utilities in non-standard locations is to define thePATH
environment in the script or use fully qualified paths to executables called. – Deathgrip Jun 14 '17 at 06:50