CCCPaste

BASH array item before and after

#!/bin/bash

array=(john jeff jerry tom tim sam andrew kris)

for i in "${!array[@]}"; do
  if [[ $i > 0 ]];then
    echo "${array[$i-1]} is before ${array[$i]} and ${array[$i+1]} is after ${array[$i]}."
  fi
done