Executing a script through "sudo" makes the script report "$0" as "/dev/fd/6" instead of expected script name
Issue
-
When executing a script through
sudo, checking$0or${BASH_SOURCE[0]}environment variable reports/dev/fd/6instead of expected script name, as shown in the example below# cat /tmp/test #!/bin/sh echo "This is $0" # sudo /tmp/test This is /dev/fd/6 -
The issue only occurs when
sudois configured to verify the checksum, e.g.%wheel ALL=NOPASSWD: sha512:... /tmp/test
Environment
- Red Hat Enterprise Linux 7 and later
- sudo
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.