Uninitialised counters are treated as 0, but still produce an error.
The redirect to stderr needs to come before the redirect for a missing
counter file.
The seemingly saner alternative of moving it outside the subshell
works when dash is /bin/sh (e.g. on Debian) but does not work when
bash is /bin/sh (e.g. on Fedora).
Signed-off-by: Martin Schwenke <mschwenke@ddn.com>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
{
_ctdb_counter_common "$1"
# unary counting!
- _val=$(wc -c <"$_counter_file" 2>/dev/null || echo 0)
+ _val=$(wc -c 2>/dev/null <"$_counter_file" || echo 0)
# Strip leading spaces from output of wc (on freebsd)
# shellcheck disable=SC2086
echo $_val