Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.88 KB | None | 0 0
  1. at the end, this code echos  "JKC: -><-", so $last_scrub is empty. why?
  2.  
  3.  
  4.     echo $scrub_list | while read scrub_entry; do
  5.         scrub_date=$(echo $scrub_entry | awk '{print $1}')
  6.  
  7.         # was this scrub history entry a scrub -s?
  8.         is_stop=0
  9.         echo $scrub_entry | egrep -q " *-s *"
  10.  
  11.         if [ "$?" = "0" ]; then
  12.             echo "found scrub -s: $scrub_entry"
  13.             is_stop=1
  14.         else
  15.             echo "found scrub: $scrub_entry"
  16.         fi
  17.  
  18.         # if 1st time (e.g. $last_scrub is empty), then set
  19.         #   last_scrub and continue
  20.         if [ -z $last_scrub ]; then
  21.             if [ "$is_stop" = "0" ]; then
  22.                 echo "INIT(last_scrub) = $scrub_date"
  23.                 last_scrub=$scrub_date
  24.             fi
  25.             # else:  if the first entry is a scrub -s (would this ever happen?) just continue
  26.             continue
  27.         else
  28.             echo "last_scrub was previously set to: $scrub_date"
  29.             # last_scrub was already set.
  30.  
  31.             # check if scrub -s, in which case we set the last scrub to the previous
  32.             if [ "$is_stop" = "1" ]; then
  33.                 echo "THIS is a scrub -s"
  34.                 if [ -z $second_to_last_scrub ]; then
  35.                     # no prior successful scrub
  36.                     echo "NO PREVIOUS SUCCESSFUL SCRUB, BLANK IT"
  37.                     last_scrub=""
  38.                 else
  39.                     echo "REUSE PREVIOUS SUCCESSFUL SCRUB: $second_to_last_scrub"
  40.                     last_scrub=$second_to_last_scrub
  41.                 fi
  42.             else
  43.                 echo "NORMAL SCRUB, UPDATE second_to_last_scrub=$last_scrub and last_scrub=$scrub_date"
  44.                 # regular scrub, update last and second_to_last
  45.                 second_to_last_scrub=$last_scrub
  46.                 last_scrub=$scrub_date
  47.             fi
  48.         fi
  49.  
  50.     done
  51.  
  52.     echo "JKC: ->$last_scrub<-"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement