TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
-r operator is a unary file test operator used within Bash conditional expressions to evaluate file existence and read permissions. It returns an exit status of 0 (true) if the specified file exists and the executing process has read access to it, based on the effective user ID. Otherwise, it returns 1 (false).
Evaluation Mechanics
- Permission Resolution: The operator evaluates the standard POSIX file permissions (owner, group, other) and Access Control Lists (ACLs) against the effective user ID (EUID) and effective group ID (EGID) of the process executing the Bash script.
- Symbolic Links: The
-roperator dereferences symbolic links. If the targetFILEis a symlink, the operator evaluates the existence and read permissions of the resolved target file, not the link itself. - Directories: In Unix-like systems, directories are treated as files. The
-roperator will return true for a directory if the executing user has read permissions for it (which permits reading the directory’s contents/listing files). - Non-existent Files: If the file does not exist in the filesystem, the operator short-circuits and evaluates to false without throwing an error.
Syntax Contexts
The operator functions identically across the three primary Bash conditional constructs, though the parsing engine differs:testbuilt-in: The POSIX-compliant command-line utility.
[ ](Single bracket): The POSIX-compliant syntactic sugar for thetestcommand. Requires spaces around the brackets and operator.
[[ ]](Double bracket): The Bash-specific extended test keyword. It handles word splitting and pathname expansion more safely than single brackets.
Disambiguation: read -r
While -r is a unary operator in the context of conditional tests, it is also frequently encountered as an option (flag) for the read built-in command (read -r). In the context of read, -r is not an operator; it is a flag that disables backslash escaping, forcing the command to treat backslashes as literal characters rather than escape sequences.
Master Bash with Deep Grasping Methodology!Learn More





