[olug] Odd results from /bin/sh (GNU bash) and the "test" command...

Kevin sharpestmarble at gmail.com
Thu Feb 25 20:36:04 UTC 2010


By incorrect behavior, I mean behavior that is contrary to what is
documented. In this case, being able to read a file whose permissions
are 0200, such as /sys/bus/pci/drivers_probe.

On Thu, Feb 25, 2010 at 12:40, Trent Melcher <trentm at q.com> wrote:
> What do you mean by incorrect behavior as root?  As root you should be able
> to read the file no matter what its permissions are set to.
>
> Trent
>
> -----Original Message-----
> From: olug-bounces at olug.org [mailto:olug-bounces at olug.org] On Behalf Of
> Kevin
> Sent: Thursday, February 25, 2010 12:13 PM
> To: Omaha Linux User Group
> Subject: Re: [olug] Odd results from /bin/sh (GNU bash) and the "test"
> command...
>
> Don't know what's going on, but my linux system(RHEL5.1/CentOS5.3
> hybrid) gives the correct behavior as a normal user, but the incorrect
> behavior as root.
>
>
> On Thu, Feb 25, 2010 at 11:38, Dan Linder <dan at linder.org> wrote:
>> I was debugging a script (CentOS 5.4 with all updated patches) that
>> was spewing errors to the screen.  The errors came from a simple "cat
>> /path/filename" and cat was reporting "Permission denied", and the
>> file had only a write permission:
>>
>> # ls -al /sys/bus/pci/drivers_probe
>> --w------- 1 root root 4096 Feb 25 10:05 /sys/bus/pci/drivers_probe
>>
>> The "test" (or [ ]) command has the -r option:
>>        -r FILE
>>               FILE exists and read permission is granted
>>
>> But a quick test shows that "-r" is saying this file is readable:
>>
>> #!/bin/sh
>> set -x
>> FILE=/tmp/notreadable
>> touch $FILE
>> chmod a-rwx $FILE
>> ls -al $FILE
>> if [ -r $FILE ] ; then
>>     echo Readable test 1
>> else
>>     echo NOT Readable test 1
>> fi
>>
>> # /tmp/testread
>> + FILE=/tmp/notreadable
>> + touch /tmp/notreadable
>> + chmod a-rwx /tmp/notreadable
>> + ls -al /tmp/notreadable
>> ---------- 1 root root 0 Feb 25 11:04 /tmp/notreadable
>> + '[' -r /tmp/notreadable ']'
>> + echo Readable test 1
>> Readable test 1
>>
>> I haven't found if this is a bug or an odd 'quirk', but it happens as
>> both a normal user and as root.
>>
>> If I'm using it incorrectly please tell me, or keep this in the back
>> of your mind if you have an odd script action...
>>
>> Very weird...still investigating it.
>>
>> Dan
>>
>> --
>> ***************** ************* *********** ******* ***** *** **
>> "Quis custodiet ipsos custodes?"
>>    (Who can watch the watchmen?)
>>    -- from the Satires of Juvenal
>> "I do not fear computers, I fear the lack of them."
>>    -- Isaac Asimov (Author)
>> ** *** ***** ******* *********** ************* *****************
>> _______________________________________________
>> OLUG mailing list
>> OLUG at olug.org
>> https://lists.olug.org/mailman/listinfo/olug
>>
> _______________________________________________
> OLUG mailing list
> OLUG at olug.org
> https://lists.olug.org/mailman/listinfo/olug
>
> _______________________________________________
> OLUG mailing list
> OLUG at olug.org
> https://lists.olug.org/mailman/listinfo/olug
>



More information about the OLUG mailing list