Bash variables: Difference between revisions

From wikinotes
 
Line 4: Line 4:
var="var"
var="var"
FOO=${VARIABLE:=default}  
FOO=${VARIABLE:=default}  
read -n 1 input  # user input to $input
</source>
</source>
</blockquote><!-- Assignment -->
</blockquote><!-- Assignment -->

Revision as of 02:04, 17 July 2021

Assignment

var="var"
FOO=${VARIABLE:=default} 

read -n 1 input  # user input to $input

test variable

test -z $var && echo "variable does not exist, or has no value"
test -n $var && echo "variable exists and has a nonzero value"

There are many more options. See man test.