Created
December 11, 2020 10:42
-
-
Save leonowski/4a2c6c5ef6273a974ed3d336c2af8082 to your computer and use it in GitHub Desktop.
bash loop through string to find first recurring character
This file contains 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 | |
#loop through characters in string taking input from first param | |
string=${1} | |
for (( i=0; i<${#string}; i++ )); do | |
#echo "${string:$i:1}" | |
for (( x=(($i + 1)); x<${#string}; x++ )); do | |
#echo XXX- "${string:$x:1}" | |
if [[ "${string:$i:1}" == "${string:$x:1}" ]] | |
then | |
echo "${string:$i:1}" | |
exit | |
fi | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment