file-test

Bash -r — read access test

Checks whether the shell identity has read access at the time of the test. It does not guarantee a later open will succeed: permissions and paths may change. Root, ACLs and filesystem policies can affect results. Run this permission fixture as an ordinary non-root user. Run the example independently in a fresh private directory. Expected output (one item per line): readable=0; blocked=1.

Formal Syntax & Structure

bash syntaxbash
[[ -r path ]]

Parameters & Attributes

NameTypeDescription
pathpathFile or directory pathname to inspect.

Return Value

exit status

0 for a true condition; 1 for a false condition. Invalid expressions may fail differently.

Working Example

Example Snippetbash
touch samplechmod 400 sample[[ -r sample ]]; printf 'readable=%s\n' "$?"chmod 000 sample[[ -r sample ]]; printf 'blocked=%s\n' "$?"
Bash Reference