Bash- How to convert non-alphanumerical character to "_"

Viewed 5329

I am trying to store user input in a variable and clean that variable in order to keep only alphanumerical caract + some others (I mean [a-zA-Z0-9-_]).

I tried using this but it isn't exhaustive :

SERVICE_NAME=$(echo $SERVICE_NAME | tr A-Z a-z | tr ' ' _ | tr \' _ | tr \" _)

Do you have some help for this?

4 Answers
Related