[olug] Odd results from /bin/sh (GNU bash) and the "test" command...
Trent Melcher
trentm at q.com
Thu Feb 25 18:39:19 UTC 2010
I wonder if its your distro, Im using rhel 5 and it works as designed a
regular user test comes back as unreadable and root test comes back as
readable. Which is what I would expect.
Trent
-----Original Message-----
From: olug-bounces at olug.org [mailto:olug-bounces at olug.org] On Behalf Of Dan
Linder
Sent: Thursday, February 25, 2010 11:39 AM
To: Omaha Linux User Group
Subject: [olug] Odd results from /bin/sh (GNU bash) and the "test"
command...
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
More information about the OLUG
mailing list