Forrest logo
back to the [[ tool

shell:warp:8cdd9

Check if file exists and is readable by the current process
$ [[ -r ${file} ]]
try on your machine

The command [[ -r ${file} ]] is a conditional expression in Bash scripting. It checks whether the file referenced by the variable file is readable or not.

Here's a breakdown of the command:

  • [[ ... ]]: This is the syntax for a conditional expression in Bash.
  • -r: This is an option used within the conditional expression, specifically to check if the following file is readable.
  • ${file}: This is a variable holding the path or name of the file you want to check for readability. The variable is enclosed within curly braces (${}) to protect it from potential word splitting or interpretation of special characters.

When this command is executed, it will evaluate to either true or false depending on whether the file referenced by the file variable is readable.

If the file is readable, the conditional expression [[ -r ${file} ]] will return true. Otherwise, it will return false. This can be used within an if statement or any other flow control structure to take further actions based on the result.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the [[ tool