Remove bashisms and simplify grep