Skip to content

Commit 6894bb2

Browse files
committed
inproved +1counter function
1 parent a87fcd9 commit 6894bb2

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

func/shared.func

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -691,29 +691,18 @@ update_user_value() {
691691

692692
increase_user_value() {
693693
USER="$1"
694-
key="$2"
695-
696-
# Defining conf
697-
conf="$V_USERS/$USER/user.conf"
698-
699-
# Deleting $
700-
key=$(echo "${key//$/}")
694+
key="${2//$}"
701695

702696
# Parsing current value
703-
current_value=$(grep "$key=" $conf |cut -f 2 -d \')
704-
705-
# Checking result
706-
if [ -z "$current_value" ]; then
707-
echo "Error: Parsing error"
708-
log_event 'debug' "$E_PARSING $V_EVENT"
709-
exit $E_PARSING
697+
conf="$V_USERS/$USER/user.conf"
698+
old=$(grep "$key=" $conf | cut -f 2 -d \')
699+
if [ -z "$old" ]; then
700+
old=0
710701
fi
711702

712-
# Plus one
713-
new_value=$(expr $current_value + 1 )
714-
715-
# Changing config
716-
sed -i "s/$key='$current_value'/$key='$new_value'/g" $conf
703+
# Increasing
704+
new=$((old + 1 ))
705+
sed -i "s/$key='$old'/$key='$new'/g" $conf
717706
}
718707

719708
is_type_valid() {

0 commit comments

Comments
 (0)