I have two bash scripts, which are binary identical, have the same permissions, are unique on my drive and are not found in sudoers. Still one passes the uid test for root, the other one not. If I call the first one with ./ in the bin folder, it behaves like the second.

The script (sync-samuel):

#!/usr/bin/env bash

echo "[$0]"

if [ "$(id -u)" != "0" ]; then
    echo "This script must be run as root"
    exit 1

id -u

The output:

samuel@xeon:~$ sync-samuel
[sudo] password for samuel: 
samuel@xeon:~$ sync-samuel2
This script must be run as root
samuel@xeon:~$ cd bin
samuel@xeon:~/bin$ ./sync-samuel
This script must be run as root

The permissions:

-rwxr-xr-x 1 samuel samuel  435 Feb  1 22:36 sync-samuel
-rwxr-xr-x 1 samuel samuel  435 Feb  1 22:37 sync-samuel2


samuel@xeon:~/bin$ file sync-samuel
sync-samuel: a /usr/bin/env bash script, ASCII text executable
samuel@xeon:~/bin$ file sync-samuel2
sync-samuel2: a /usr/bin/env bash script, ASCII text executable

Does anyone know, what triggers this behaviour or how I can view extended properties of these two files? I'm using Lubuntu 14.04 LTS w/ bash 4.3.11(1)-release.

Edit: G-Man ist the man! The first one is also an alias:

samuel@xeon:~/bin$ type sync-samuel2
sync-samuel2 is hashed (/home/samuel/bin/sync-samuel2)
samuel@xeon:~/bin$ type sync-samuel
sync-samuel is aliased to `sudo /home/samuel/bin/sync-samuel'
  • 6
    Do you have any clue how/why sync-samuel is giving you a sudo dialog when it doesn't call sudo?  Type type sync-samuel and type sync-samuel2 and see whether that helps you.  Please do not post clarifying information in comments; if you have additional information to provide, edit your question to make it clearer and more complete. – G-Man Says 'Reinstate Monica' Feb 2 '16 at 18:50
  • What exactly are you trying to do here? This test is common and is working properly. Your output tells me that samuel is not in your sudo'ers file. The question is why does whoami return 0 in the first case. – eyoung100 Feb 2 '16 at 18:55

Your output shows that sync-samuel issues a sudo prompt, even though you run it without sudo and the script itself doesn’t invoke sudo.  This doesn’t make any sense.  It looks like, when you type sync-samuel, you’re running something other than the sync-samuel script that you show in the question.

It is possible that sync-samuel is actually an alias for sudo sync-samuel or something similar.  Another possibility is that you have another copy of sync-samuel in another directory, and your shell is finding (and running) it rather than the copy you’re looking at.  To diagnose this, issue the following command:

type sync-samuel sync-samuel2

type is a built-in command that shows how the shell interprets each command.  If you get substantially different responses for the two files (e.g., sync-samuel is an alias and sync-samuel2 is not), you will know how to proceed to cause them to be handled the same (e.g., define an alias for sync-samuel2, too).

| improve this answer | |
  • 2
    I think the path the script prints out rules out another script with the same name. The alias (or a shell function) seems a plausible reason. – orion Feb 3 '16 at 12:46
  • Good point — I overlooked that. – G-Man Says 'Reinstate Monica' Feb 3 '16 at 18:02

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.