Skip to content

Instantly share code, notes, and snippets.

@inceabdullah
Created April 24, 2024 12:13
Show Gist options
  • Save inceabdullah/ea805b5388036d6df6c3d1802f66e483 to your computer and use it in GitHub Desktop.
Save inceabdullah/ea805b5388036d6df6c3d1802f66e483 to your computer and use it in GitHub Desktop.
SNAKE_CASE to camelCase
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