Advertisement
metalx1000

BASH array item before and after

Jan 21st, 2022
1,138
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. array=(john jeff jerry tom tim sam andrew kris)
  4.  
  5. for i in "${!array[@]}"; do
  6.   if [[ $i > 0 ]];then
  7.     echo "${array[$i-1]} is before ${array[$i]} and ${array[$i+1]} is after ${array[$i]}."
  8.   fi
  9. done
  10.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement