Closed radio24 closed 3 years ago
There is no reason to be always set to one, it is a bug.
I've come with some solutions:
CLIENT_COUNT="$(printf %s"${CLIENT_NAME_LIST}" | tr -dc "," | wc -c)"
[ -n "${CLIENT_COUNT}" ] && CLIENT_COUNT=$((CLIENT_COUNT+1))
CLIENT_COUNT="$(printf %s"${CLIENT_NAME_LIST}" | awk -F, '{print $1}')"
Awk was actually the old way, but as I try to minimize external commands, I got rid of awk
because it is not installed on many distros and tr
and wc
are. But awk counts it correctly the clients and wc just counts the delimiters, which end up with me adding a +1 to make it correct.
I don't like any of the above methods and I am trying to find the best way to do that with the commands that I already use the most on the code. I will keep this open to find a solution that does not involve awk or wc.
Possible will be like this https://github.com/nyxnor/onionservice/blob/aee0d65029c50bf52aa9715950056f4cdb397765/onionservice-tui#L329
CLIENT_COUNT=$(IFS=','; set -f -- ${CLIENT_NAME_LIST}; printf %s"${#}")
https://github.com/nyxnor/onionservice/blob/717de24f14403248a69800d244bc8dc3c2bb2972/onionservice-cli#L131
Issue
CLIENT_COUNT
is always set to1
. This means that if[ -n "${CLIENT_COUNT}" ]; then
(for example here) will never executed.Describe the solution you'd like To remove the specific line of code If there is no other reason for
CLIENT_COUNT=$((CLIENT_COUNT+1))