...
5 declare desc="A simple countdown. Source: https://superuser.com/a/611582"
6 local seconds="${1}"
7 local d=$(($(date +%s) + "${seconds}"))
8 while [ "$d" -ge `date +%s` ]; do 9 echo -ne "$(date -u --date @$(($d - `date +%s`)) +%H:%M:%S)\r";
10 sleep 0.1
11 done
...
6 local seconds="${1}"
7 local d=$(($(date +%s) + "${seconds}"))
8 while [ "$d" -ge `date +%s` ]; do
9 echo -ne "$(date -u --date @$(($d - `date +%s`)) +%H:%M:%S)\r";10 sleep 0.1
11 done
12}
Consider using the $(...)
notation instead.
Backtick command substitution \
...`` is legacy syntax with several issues.
* It has a series of undefined behaviors related to quoting in POSIX.
* It imposes a custom escaping mode with surprising results.
* It's exceptionally hard to nest.
$(...)
command substitution has none of these problems, and is therefore strongly encouraged.
echo "You are running on `uname`"
echo "You are running on $(uname)"
Read more about it here:
- BashFq: Why is $(...)
preferred over \
...`` (backticks)?.