title: What do [ -r $1 ] and [ ! -r $1 ] mean in Bash?
body: <p>I learned that -r means recursive, which means the command can be performed in all subdirectories. To make sure I understand, I wrote the two functions below to make some tests. The file where I wrote the following code was named as test.sh. Inside the same directory I have a sub-directory called subtest. There's a file named xx.sh either in the current directory of in the sub-directory.</p>
  
  <pre><code>#!/bin/bash
  function aa {
    if [ ! -r $1 ]
    then
      echo "not exist"
    else
      echo "exist"
    fi
  }
  
  function bb {
    if [ -r $1 ]
    then
      echo "exist"
    else
      echo "not exist"
    fi
  }
  
  aa xx.sh / bb xx.sh
  </code></pre>
  
  <p>The results I found: </p>
  
  <p>For aa function, with <code>-r</code>, it will only print "exist" if xx.sh is in the current directory. It won't look for xx.sh in the sub-directory. Without <code>-r</code>, it will print "exist" when xx.sh is either in current directory or in the subdirectory. </p>
  
  <p>For bb function, with <code>-r</code>, it will only print "exist" when the current directory has xx.sh.  Without <code>-r</code>, it will always print "exist", even if there is no xx.sh at all (which surprised me and does not make sense!). </p>
  
  <p>Can anyone explain why the results above happen and what does -r do exactly?</p>