Skip to main content
added 108 characters in body
Source Link
yolenoyer
  • 9.3k
  • 2
  • 31
  • 66

Another way of using booleans is to test the emptyness of values. This has the advantage of making shorter tests:

one=1first=1  # A true value
two=second=   # A false value

[ -n "$one""$first" ]  && echo "One'First var is true"true'
[ -z "$one""$first" ]  && echo "One'First var is false"false'
[ -n "$two""$second" ] && echo "Two'Second var is true"true'
[ -z "$two""$second" ] && echo "Two'Second var is false"false'

Output:

First var is true
Second var is false

Here is an alternative test syntax with bash: [[ -n $one ]]

Another way of using booleans is to test the emptyness of values. This has the advantage of making shorter tests:

one=1  # A true value
two=   # A false value

[ -n "$one" ] && echo "One is true"
[ -z "$one" ] && echo "One is false"
[ -n "$two" ] && echo "Two is true"
[ -z "$two" ] && echo "Two is false"

Here is an alternative test syntax with bash: [[ -n $one ]]

Another way of using booleans is to test the emptyness of values. This has the advantage of making shorter tests:

first=1  # A true value
second=   # A false value

[ -n "$first" ]  && echo 'First var is true'
[ -z "$first" ]  && echo 'First var is false'
[ -n "$second" ] && echo 'Second var is true'
[ -z "$second" ] && echo 'Second var is false'

Output:

First var is true
Second var is false

Here is an alternative test syntax with bash: [[ -n $one ]]

added 2 characters in body
Source Link
yolenoyer
  • 9.3k
  • 2
  • 31
  • 66

Another way of using booleans is to test the emptynessemptyness of values. This has the advantage of making shorter tests:

one=1  # A true value
two=   # A false value

[ -n "$one" ] && echo "One is true"
[ -z "$one" ] && echo "One is false"
[ -n "$two" ] && echo "Two is true"
[ -z "$two" ] && echo "Two is false"

Here is an alternative test syntax with bash: [[ -n $one ]]

Another way of using booleans is to test the emptyness of values. This has the advantage of making shorter tests:

one=1  # A true value
two=   # A false value

[ -n "$one" ] && echo "One is true"
[ -z "$one" ] && echo "One is false"
[ -n "$two" ] && echo "Two is true"
[ -z "$two" ] && echo "Two is false"

Here is an alternative test syntax with bash: [[ -n $one ]]

Another way of using booleans is to test the emptyness of values. This has the advantage of making shorter tests:

one=1  # A true value
two=   # A false value

[ -n "$one" ] && echo "One is true"
[ -z "$one" ] && echo "One is false"
[ -n "$two" ] && echo "Two is true"
[ -z "$two" ] && echo "Two is false"

Here is an alternative test syntax with bash: [[ -n $one ]]

Source Link
yolenoyer
  • 9.3k
  • 2
  • 31
  • 66

Another way of using booleans is to test the emptyness of values. This has the advantage of making shorter tests:

one=1  # A true value
two=   # A false value

[ -n "$one" ] && echo "One is true"
[ -z "$one" ] && echo "One is false"
[ -n "$two" ] && echo "Two is true"
[ -z "$two" ] && echo "Two is false"

Here is an alternative test syntax with bash: [[ -n $one ]]