Advertisement
metalx1000

BASH array item before and after

Jan 21st, 2022
1,682
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.22 KB | None | 0 0
  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
Add Comment
Please, Sign In to add comment
Advertisement