Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does -z mean in Bash? [duplicate]

Tags:

bash

People also ask

What is $1 and $2 in bash?

$1 is the first argument (filename1) $2 is the second argument (dir1)

What does #$ mean in bash?

#$ does "nothing", as # is starting comment and everything behind it on the same line is ignored (with the notable exception of the "shebang"). $# prints the number of arguments passed to a shell script (like $* prints all arguments). Follow this answer to receive notifications. edited Jul 9 at 13:55.

What does $2 do in bash?

$2 is the second command-line argument passed to the shell script or function. Also, know as Positional parameters.

What is &2 in bash script?

and >&2 means send the output to STDERR, So it will print the message as an error on the console. You can understand more about shell redirecting from those references: https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Redirections.


-z string True if the string is null (an empty string)


-z

string is null, that is, has zero length

String=''   # Zero-length ("null") string variable.

if [ -z "$String" ]
then
  echo "\$String is null."
else
  echo "\$String is NOT null."
fi     # $String is null.

test -z returns true if the parameter is empty (see man sh or man test).


The expression -z string is true if the length of string is zero.