In a bash script, how do I sanitize user input?

前端 未结 6 1080
抹茶落季
抹茶落季 2020-12-24 05:01

I\'m looking for the best way to take a simple input:

echo -n \"Enter a string here: \"
read -e STRING

and clean it up by removing non-alph

6条回答
  •  北海茫月
    2020-12-24 05:44

    Quick and dirty:

    STRING=`echo 'dit /ZOU/ een test123' | perl -pe's/ //g;tr/[A-Z]/[a-z]/;s/[^a-zA-Z0-9]//g'`

提交回复
热议问题