Bash: make PS2 more robust, fix bugs