Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

-z option inside if condition in shell script

Can someone post me the significance of -z option while writing if condition using shell scripts.

Let me paste the exact condition what I am looking at

if [[ "x$do_clean_flag" = "x-clean" && -z "$show_me_flag" && "$verify" = true ]] 
like image 588
Nageswara Rao Avatar asked Apr 08 '11 10:04

Nageswara Rao


People also ask

What is option in if condition in Linux?

if is a command in Linux which is used to execute commands based on conditions. The 'if COMMANDS' list is executed. If its status is zero, then the 'then COMMANDS' list is executed.

How do you write an if-else condition in shell script?

If specified condition is not true in if part then else part will be execute. To use multiple conditions in one if-else block, then elif keyword is used in shell. If expression1 is true then it executes statement 1 and 2, and this process continues. If none of the condition is true then it processes else part.

What is $# in shell script?

$# : This variable contains the number of arguments supplied to the script. $? : The exit status of the last command executed. Most commands return 0 if they were successful and 1 if they were unsuccessful. Comments in shell scripting start with # symbol.

Can you use if statements in bash script?

What is the Bash if Statement? Bash scripts help automate tasks on your machine. The if elif else statement in bash scripts allows creating conditional cases and responses to specific code results. The if conditional helps automate a decision-making process during a program.


1 Answers

From "help test":

-z STRING      True if string is empty. 
like image 131
Erik Avatar answered Oct 26 '22 19:10

Erik