Add some logic to better support bash shells

Fix #533