0

I'm interested in:

if [ -z "${var// }" ]...

if [ -d $dir ]...

More precisely, what is -z and -d? How can I call it and where can I read about this "keys"? And where can i find a full list of this "keys"?

Pro
  • 673
  • 2
  • 6
  • 15

3 Answers3

1

Look at the manpage for test

man test
Rob Hales
  • 5,123
  • 1
  • 21
  • 33
1

-z variable will check condition if a variable is NULL then the condition will be TRUE if NOT then it will go to else part of if condition.

-d directory_name will check if a directory name which is given next to it is present or not. If directory is present then condition will be TRUE or it will be FALSE.

From man test

-z STRING

the length of STRING is zero

-d FILE

FILE exists and is a directory

RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
1

in bash manual invoked using

 man -a bash

a section called CONDITIONAL EXPRESSIONS which covers what you are looking for, in fact there are a whole bunch of basic to advanced concepts in there to look for.

asio_guy
  • 3,667
  • 2
  • 19
  • 35