0

I have a script that needs sudo permissions and needs to be run with /bin/bash on an Ubuntu 14.04 machine.

If I run it while logged in as root (or any other user) it opens with /bin/bash as expected, however when I run the script with sudo it opens with /bin/sh no matter what user I'm logged in as.

I've checked /etc/passwd and I see /bin/bash is the default shell for root. $SHELL is defined as /bin/bash as well.

I won't be the only one using the script, so I can't rely on people using sudo -i to run it.

Where is the sudo shell defined? How can I change it?

7
  • 1
    Have you tried setting the shell using a #! line in the script?
    – Jesusaur
    Commented Nov 25, 2018 at 11:52
  • 1
    Add to your script as first line : #!/bin/bash
    – harrymc
    Commented Nov 25, 2018 at 12:17
  • Right, I forgot to mention I already set the shell that way. It didn't help. I'll edit the question
    – stav meir
    Commented Nov 25, 2018 at 12:47
  • I just double-checked, I did have #!/bin/bash in the script but not as the first line! I had some comments about the script beforehand, old python habits I guess. I've changed their order and the script opens with bash! Thanks. I can't upvote your comments :/
    – stav meir
    Commented Nov 25, 2018 at 12:50
  • Please don't edit the answer into your question. Super User is a question and answer site and answers should be separate from questions. You can answer your own question instead.
    – DavidPostill
    Commented Nov 25, 2018 at 13:06

1 Answer 1

1

My problem was that I documented the script before the #!/bin/bash line, so the shebang wasn't the first line in the script.

You must log in to answer this question.

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