Skip to content

Instantly share code, notes, and snippets.

@l0b0
Created November 10, 2010 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save l0b0/671067 to your computer and use it in GitHub Desktop.
Save l0b0/671067 to your computer and use it in GitHub Desktop.
test_bash_set.sh
#!/bin/bash
echo ' ${var-_} ${var:-_} $var ${!var[@]}'
test_all()
{
test "${var-_}" && echo -n 'T ' || echo -n 'F '
test "${var:-_}" && echo -n 'T ' || echo -n 'F '
test "$var" && echo -n 'T ' || echo -n 'F '
[[ "${!var[@]}" ]] && echo 'T' || echo 'F'
}
declare var
echo -n 'unset '
test_all
var=''
echo -n 'empty '
test_all
var=' '
echo -n 'non-empty '
test_all
var=(var1 var2 var3)
echo -n 'array '
test_all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment