Check if element exists in array in bash

May 02, 2012

Reading time ~1 minute

Here’s a little function to verify if an element exists in a Bash array.

function elementExists() {
    for i in ${elements[@]} ; do
        if [ $i == $element ] ; then
            return 1
    return 0

It takes an array as first argument and the element as the second and will return 1 if the element exists in the array. You can now call the function like this:

elementExists my_array my_element

Running vim-airline with Maximum Awesome

I use [Maximum Awesome]( when I code in [vim](, it's a great starting place...… Continue reading

Quicksort implementation in Python

Published on August 04, 2014

Fibonacci generator in Python

Published on August 04, 2014