I am writing a script that removes vowels from a string while preserving sequential white spaces, here is my code:
#!/bin/bash
result=""
for (( i = 0; i < ${#1}; i++ )); do
[[ "${1:$i:1}" =~ [^aeiouAEIOU] ]] && result+="${1:$i:1}"
done
echo $result
It executes properly for example:
[user@localhost ~]$ bash remove_vowels.sh "Hi it's me" H t's m #vowels removed successfully
But when my argument contains multiple white spaces:
[user@localhost ~]$ bash remove_vowels.sh "Hi it's me" H t's m #Whitespaces are gone
What do I need to change so my code work as desired?