I'm trying to run the following script on an install of Fedora 20.

echo "$password" | sudo -Sk /bin/bash -c '[[ $EUID -eq 0 ]]'
[[ $? -ne 0 ]] && zenity --error --text failed. || zenity --error --text success.

When trying to run from a terminal emulator, it reports success, but when double clicking the script from a file manager (Thunar in this case), it reports failure.

On some other distros (e.g. Debian Wheezy), I get a consistent behaviour.

Why would that be the case and what should I do to solve this problem?

  • It's usually not a good idea to mention that "failure is reported" without quoting the error message... – Hauke Laging Jan 18 '15 at 5:16
  • Hopefully the downvoter would explain why... – user2064000 Jan 18 '15 at 6:18
  • @HaukeLaging: As in: zenity --error --text failed. is executed. – user367890 Jan 18 '15 at 6:52
  • Is the stdout and stderr from the script available anywhere? Perhaps you could redirect the output of the sudo so you can see what actually happened? – Danny Staple Jan 18 '15 at 12:04
  • Putting your password in a script is a bad idea. Instead, let the user enter the password, or configure sudo to run the command without a password. – Gilles Jan 18 '15 at 23:25

In the /etc/sudoers file (accessible with visudo), look for requiretty. You can turn this off for the program with:

Defaults!/path/to/program !requiretty

In your case - you are using bash, so this path would be whatever you get from which bash.


You should verify that sudo doesn't require tty in the /etc/sudoers file (requiretty should not be set).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.