Issue
I have three if conditions in a shell script I have been given, can I be assisted with what they each mean in English. Also, how would I use the man pages to find out similar commands in the future?
The conditions are as follows:
if [ -z $1 ]
if [ ! -r $1 ]
if [ -n $3 ]
Solution
The trick here is that [
is not punctuation, but the name of a command, which is also called test
. So the help page you need is man test
.
On that page, you can see the options listed:
-z STRING
the length of STRING is zero
! EXPRESSION
EXPRESSION is false
-r FILE
FILE exists and read permission is granted
-n STRING
the length of STRING is nonzero
Since bash includes a built-in implementation of this command, you can also find the information under man bash
and in the bash reference manual.
Answered By - IMSoP