even more robust bash snippet