Ceci est une ancienne révision du document !
Bash
in_array
function in_array() { local needle=$1 el shift for el in "$@"; do if [ "$el" = "$needle" ]; then return 0 fi done return 1 } array=(1 2 3) in_array 1 ${array[@]} && echo IN in_array 5 ${array[@]} && echo OUT
implode
function implode() { local d=${1-} f=${2-} if shift 2; then printf %s "$f" "${@/#/$d}" fi } array=(1 2 3) echo $( implode "," "${array[@]}" ) # Output: 1,2,3 echo -e "- $( implode "\n- " "${array[@]}" )" # Output: # - 1 # - 2 # - 3