Linux shell debug

< hr > I don"t understand this paragraph in

figure. If you can, please describe this syntax rule and calling sequence in detail. Thank you

.

figure code:

-sharp!/bin/bash
function DEBUG()
{
    [ "$_DEBUG" == "on" ] && $@ || :
}
for i in {1..10}
do
    DEBUG echo $i
done
< hr >

May.07,2022

["$_ DEBUG" = = "on"] & & $@ | |:
This sentence is divided into three parts

  1. ["$_ DEBUG" = = "on"]
    this is a conditional expression that checks whether the value of the environment variable _ DEBUG is equal to on .
  2. $@
    this executes the function argument as a command. In this case, the function argument is "echo xx".
  3. :
    this is an empty command, do nothing.

these three parts are connected in series by & & and | to form cond & & cmd1 | | cmd2 structure.
means that cmd1 is executed when the cond condition is true, otherwise cmd2 .

Menu