Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.41 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. inarray() { local n=$1 h; shift; for h; do [[ $n = "$h" ]] && return; done; return 1; } # Usage: inarray "$value" "${array[@]}"
  4.  
  5. files=("test" "foo" "foo" "bar" "test")
  6. inc=1
  7. for filename in "${files[@]}"; do
  8.     if ! inarray "$filename" "${filelist[@]}"; then
  9.         filelist+=("$filename")
  10.     else
  11.         filelist+=("$filename""$inc")
  12.         ((inc++))
  13.     fi
  14. done
  15.  
  16. echo "${filelist[*]}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement