Variables


Table of Contents

Variables checking & usage 
check set 
check empty 
use if set (use as default) 
use different if set (change default) 
Change a bit if a variable defined 
do if variable not set 
Variable initialisation and sh syntax 
default values 
Help 
internal variables and sub-shell 
Variable pattern testing 
Sample 0, one line 
Sample 1 
Sample 2 
Sample: case sensitives 
variable buildup 
Goal 
Solution 
Trying History 
variable interpolate 
2nd level 
3rd level 
determine a compressed file type by sed 
Ways to test on string length 
Ways to test on string length 
Ways to test on string length 
get first 4 characters of variable 
how to check if $var has an letter B in it? 
pass on arguments exactly as received 
shell scripts 
${3+"$3"}<<, >>
Passing VARS between Shells 

Variables checking & usage 

*Tags*: empty check, test empty

check set 

${VAR+T} True if VAR is set, even if it is empty

check empty 

${VAR:+T} True if VAR is set and non-null

use if set (use as default) 

${VAR:-default_value} use the value of VAR if VAR is set and non-null,
   otherwise use "default_value"

use different if set (change default) 

${VAR:+value} return "value" if VAR is set and non-null,
   otherwise return VAR