I am no expert in shell scripts and as I read one of the lines in a bash script, I see this:
if [[ ! -r test.json ]]
then
printf "no test.json here\n" >&2
exit 1
fi
What does the line if [[ ! -r test.json ]]
option do? From the logic, it seems like it checks if the file test.json
does not exist. I did some research to see what all options are indeed provided in a shell command, but I don't see the -r
option here: https://tldp.org/LDP/abs/html/options.html
CodePudding user response:
-r
is one of many possible arguments for the [
-program and the [[
bash construct (which is what you're using here).
-r
checks if the argument that follows it is a file, it exists, and it's readable.
A bash cheatsheet can be useful for these things while making shell scripts
CodePudding user response:
You're looking in the wrong part of the documentation. It's not a shell option, it's a conditional expression operator.
-r file
True if file exists and is readable.
The !
operator inverts the condition, so this tells you if test.json
doesn't exist or is not readable.