Advertisement
metalx1000

BASH before and after loop

Jan 21st, 2022
1,235
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. echo "john
  4. jeff
  5. jerry
  6. tom
  7. tim
  8. sam
  9. andrew
  10. kris" > /tmp/names
  11.  
  12.  
  13. let x=0
  14.  
  15. cat /tmp/names |while read line
  16. do
  17.   if [[ "$name1" != "" ]]
  18.   then
  19.     echo "$name1 is before $name2 and $line is after $name2"
  20.   fi
  21.     name1="$name2"
  22.     name2="$line"
  23.   let x++
  24.  
  25. done
  26.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement