Created
April 24, 2024 12:13
-
-
Save inceabdullah/ea805b5388036d6df6c3d1802f66e483 to your computer and use it in GitHub Desktop.
SNAKE_CASE to camelCase
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
snake_to_camel() { | |
local input="$1" | |
local result="" | |
local capitalize_next=false | |
# Loop through each character in the input string | |
for (( i=0; i<${#input}; i++ )); do | |
char="${input:i:1}" | |
# Check if the character is an underscore | |
if [[ "$char" == "_" ]]; then | |
capitalize_next=true | |
elif $capitalize_next; then | |
capitalize_next=false | |
result+="$char" | |
else | |
result+=$(echo "$char" | tr '[:upper:]' '[:lower:]') | |
fi | |
done | |
echo "$result" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment