Shell prompt that is based on location in filesystem

view story

http://stackoverflow.com – I have to work within three main directories under the root filesystem - home/username, project, and scratch. I want my shell prompt to display which of these top level directories i am in. Here is what I am trying to do: top_level_dir () { if [[ "${PWD}" == *home* ]] then echo "home"; elif [[ "${PWD}" == *scratch* ]] then echo "scratch"; elif [[ "${PWD}" == *project* ]] then echo "project"; fi } Then, I export PS1 as: export PS1='$(top_level_dir) : ' Unfortunately this is not working as I want. I get home : for my prompt when I am in (HowTos)