title: Shell script for loop outputs unordered sequence of numbers
body: <p>I wrote shell script like this below and outputs like</p>
  
  <pre><code>redis-health-checker: Ping failed 1
  redis-health-checker: Ping failed 3
  redis-health-checker: Ping failed 2
  </code></pre>
  
  <p>but It was supposed to output like </p>
  
  <pre><code>redis-health-checker: Ping failed 1
  redis-health-checker: Ping failed 2
  redis-health-checker: Ping failed 3
  </code></pre>
  
  <p>( This script is a simple check-script to see if redis-server is alive or not and tell Keepalived if it stops working. )</p>
  
  <pre><code>#!/bin/bash
  
  for TRIES in $(seq 1 3)
  do
    RESULT=$($REDIS_CLI ping)
    if [ "${/etc/redis-cli}" = "PONG" ]; then
      exit 0
    fi
    echo "Ping failed ${TRIES}" | logger -t redis-health-checker
    sleep 1
  done
  
  exit 1 # Makes Keepalived FALL
  </code></pre>