-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_var.sh
executable file
·25 lines (22 loc) · 1.22 KB
/
check_var.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/bash
# example of variable dereferencing in bash (known as 'indirect expansion')
check_var()
{
local ENV_VAR=$1
if [[ -v ${ENV_VAR} ]]; then
echo "pass variable $ENV_VAR is set"
else
echo "fail variable $ENV_VAR is undefined"
fi
if [[ -d ${!ENV_VAR} ]]; then
echo "pass variable $ENV_VAR points to existing directory"
else
echo "fail variable $ENV_VAR points to directory which doesn't exist"
fi
}
TMP_HOME=/home/martin/tmp
FOO_HOME=/home/martin/foo
unset NOO_HONE
for ENV_VAR in {TMP,FOO,NOO}_HOME; do
check_var $ENV_VAR
done