Last active
June 13, 2022 22:18
-
-
Save KartaviK/f975c1fbce642eea384a4433f0c9ea90 to your computer and use it in GitHub Desktop.
Function to get index of needs element in array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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