help with a bash script please

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Gregory Nowak said the following on Sat, Apr 08, 2006 at 03:16:56PM -0700:
> I'm having trouble with an if statement in a bash script I'm
> writing. What I want to do, is to check if a file doesn't have read
> permission. What I'm doing is:
> 
> if !([ -r filename])


Try this:

if [ ! -r filename ]; then

That should work. I tried this on a file called test with chmod 000 
then chmod 666 and on 000 the script was true due to the exclamation 
but false when the file was chmod 666 since the script then made it 
false.

The quick script I wrote is as follows:

#!/bin/bash

if [ ! -r test ]; then
echo "this file is not readable"
else
echo "this file is readable"
fi

HTH.

-- 
All I want is a warm bed and a kind word and unlimited power.
		-- Ashleigh Brilliant
Raul A. Gallegos ... IliwSsmc




[Index of Archives]     [Linux for the Blind]     [Fedora Discussioin]     [Linux Kernel]     [Yosemite News]     [Big List of Linux Books]
  Powered by Linux