I needed to remove spaces and capital letters to various strings of text like:
"My Name is Mauro" -> "my_name_is_mauro"
So I have created this bash script:lowercase_underscore.sh
(call it the same for testing). Is there another way to accomplish this with a loop?
#!/bin/bash
echo "Please enter a word:
(leave blank and press Enter to exit)"
# read user input
read foobar
# exit
if [[ $foobar == '' ]]; then
exit
fi
# convert upper case to lower
foobar=$(echo "$foobar" | tr '[:upper:]' '[:lower:]')
# strip underscore and apostrophe
foobar=${foobar// /_}
foobar=${foobar//\'/}
# output
echo "########
"
echo "machine_name_"${foobar}
echo "
########"
# loop - execute itself (this could go against the Three Laws of Robotics)
bash lowercase_underscore.sh