0

I am trying to run a shell script with elevated privileges on photon os by using su.

When doing this though I get an error Unknown command: `./install-salt.sh'

The command I am running with su is: su -c './install-salt.sh'

Any help appreciated

1 Answer 1

1

When you write ./install-salt.sh that is a relative path, since . means current directory. You should use an absolute path like /home/you/install-salt.sh instead since the shell you're spawning to run that command has another idea of what the "current directory" is.

Using absolute paths is good practice in other situations too, like cronjobs for example, or systemd configurations, where they are often required.

Also, in your case, ensure the file is executable (permission +x).

6
  • I put the file in /usr/local/bin/install-salt.sh and point to that in my command as follows su -c '/usr/local/bin/install-salt.sh' however I still get the same issue. How do I ensure the file is an executable?
    – anthony
    Commented Apr 5, 2023 at 10:22
  • 1
    go to /usr/local/bin/ and run chmod +x install-salt.sh, then verify it by running ls -l install-salt.sh
    – pzkpfw
    Commented Apr 5, 2023 at 10:24
  • 1
    Note that it only works to run a shell script immediately like this if it begins with something like #!/bin/bash which tells it how to run it. If you miss that, add it or tell the command explicitly to have bash run it, like su -c '/bin/bash [filename]'
    – pzkpfw
    Commented Apr 5, 2023 at 10:25
  • When I put in the /bin/bash I get the same error again, Unknown command.
    – anthony
    Commented Apr 5, 2023 at 10:46
  • Try #! /bin/sh I made a quick shellscript (that only exits itself) as a testbed and it seems to work. Make sure it has execute permissions as well, of course. Commented Apr 5, 2023 at 11:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .