DEFAULT=5
RESULT=${VAR:-$DEFAULT}
function rollback() {
if [[ $? -ne 0 ]]; then
echo "rollback"
fi
}
set -ueo pipefail
trap rollback EXIT
#!/bin/bash
FILE="/etc/passwd"
if [[ -f $FILE ]];then
echo "$FILE exists"
else
echo "$FILE doesn't exist"
fi
#!/bin/bash
DIR="/var/log"
if [[ -d $DIR ]]; then
echo "$DIR exists"
else
echo "$DIR doesn't exist"
fi
function assert_var_exists() {
local condition="[[ ! -n \"\${$1+set}\" ]]"
if eval $condition; then
echo "The variable ${1} does not exist. Exit."
exit 1
fi
}
function export_var() {
assert_var_exists $1
local var_value=$(($1))
eval "export $1=\$var_value"
echo "$1=$var_value"
}