<html><p><br>
I have to write some BASH scripts.</p><p>We have all heard about security problems with shell variables</p><p>(i.e. when entering a name someone enters something like "Tony; rm -rf /root/*" )</p><p>so that if the BASH scripts echoes it will will do something like echo Tony; rm -rf /root/*.</p><p> </p><p>Now we have honest users here, but I still want to do some checks.  If I read in or get a shell variable from a user</p><p>I could do something like</p><p> </p><p>    echo "$VAR" | grep '[^a-zA-Z/_-]'</p><p>    if [ $? -eq 0 ]</p><p>    then</p><p>        echo "You have entered a bad character"</p><p>        exit 1</p><p>    fi</p><p> </p><p>but that still runs into the problem like above with the echo.  I also could do</p><p> </p><p>case "$VAR" in</p><p> </p><p>    \;|\:) echo "you have a bad character"    </p><p>        ;;</p><p> </p><p>esac</p><p> </p><p> </p><p>but I am not sure that is best either.  Is there anyway to validate shell variables?</p><p>I know Javascript, etc., has something like url_encode() </p></html>