Skip to content

Instantly share code, notes, and snippets.

@KartaviK
Last active June 13, 2022 22:18
Show Gist options
  • Save KartaviK/f975c1fbce642eea384a4433f0c9ea90 to your computer and use it in GitHub Desktop.
Save KartaviK/f975c1fbce642eea384a4433f0c9ea90 to your computer and use it in GitHub Desktop.
Function to get index of needs element in array
#!/bin/bash
function index_of() {
index=0;
for arg in ${@:2}; do
index=$((index + 1))
if [[ ${1} == ${arg} ]]; then
echo ${index};
break;
fi
done
}
echo $(index_of ${1} ${@:2})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment