gsu_is_a_number()
{
result="$1"
- if test "$1" -eq "$1" &> /dev/null; then
+ if (("$1" == "$1")) &> /dev/null; then
ret=$GSU_SUCCESS
else
ret=-$E_GSU_NOT_A_NUMBER
local txt="$result" err
gsu_is_a_number "$ret"
- if test $ret -lt 0; then
+ if (($ret < 0)); then
gsu_msg "unknown error ($ret:$txt)"
exit 1
fi
- if test $result -ge 0; then
+ if (($result >= 0)); then
gsu_msg "unknown error ($result:$txt)"
exit 1
fi
result="name: '$name'"
# bash's =~ works only for 3.2 and newer, so use grep
echo "$name" | grep '^[a-zA-Z][a-zA-Z_0123456789]*$' &> /dev/null;
- [[ $? -ne 0 ]] && return
+ (($? != 0)) && return
eval orig_val='"'\$orig_${gsu_config_var_prefix}_$name'"'
if [[ -z "$orig_val" ]]; then
;;
num)
gsu_is_a_number "$val"
- [[ $ret -lt 0 ]] && return
+ (($ret < 0)) && return
;;
*)
ret=-$E_GSU_BAD_OPTION_TYPE
ret=-$E_GSU_MKDIR
result="${conf%/*}"
mkdir -p "$result"
- [[ $? -ne 0 ]] && return
+ (($? != 0)) && return
ret=-$E_GSU_EDITOR
result="${EDITOR:-vi}"
"$result" "$conf"
- [[ $? -ne 0 ]] && return
+ (($? != 0)) && return
ret=$GSU_SUCCESS
return
fi
_gsu_available_commands
for com in $result; do
num=${#com}
- if test $num -lt 4; then
- num=4
- fi
+ (($num < 4)) && num=4
echo "${minus_signs:0:$num}"
echo "$com"
echo "${minus_signs:0:$num}"
'
gsu_check_arg_count $# 1 1
- if [[ $ret -lt 0 ]]; then
+ if (($ret < 0)); then
gsu_err_msg
exit 1
fi
_gsu_setup
_gsu_available_commands
gsu_cmds="$result"
- if test $# -eq 0; then
+ if (($# == 0)); then
_gsu_usage
_gsu_print_available_commands
exit 1
# check internal commands
if [[ "$arg" = "help" || "$arg" = "man" || "$arg" = "prefs" || "$arg" = "complete" ]]; then
_com_$arg "$@"
- if [[ "$ret" -lt 0 ]]; then
+ if (("$ret" < 0)); then
gsu_err_msg
exit 1
fi
for i in $gsu_cmds; do
if test "$arg" = "$i"; then
com_$arg "$@"
- if [[ "$ret" -lt 0 ]]; then
+ if (("$ret" < 0)); then
gsu_err_msg
exit 1
fi
gsu_check_arg_count()
{
ret=-$E_GSU_BAD_ARG_COUNT
- if [[ $# -eq 2 ]]; then # only num1 is given
+ if (($# == 2)); then # only num1 is given
result="at least $2 args required, $1 given"
- [[ $1 -lt $2 ]] && return
+ (($1 < $2)) && return
ret=$GSU_SUCCESS
return
fi
# num1 and num2 given
result="need at least $2 args, $1 given"
- [[ $1 -lt $2 ]] && return
+ (($1 < $2)) && return
result="need at most $3 args, $1 given"
- [[ $1 -gt $3 ]] && return
+ (($1 > $3)) && return
ret=$GSU_SUCCESS
}