Programming Tips - bash: How can I check that a cd in a bash script worked?

Date: 2017oct13 Language: bash Keywords: success, die Q. bash: How can I check that a cd in a bash script worked? A.
if cd /tmp; then echo Worked else echo Failed fi
If you want the script to end when the cd fails
if cd /tmp; then : # This means do nothing on success else echo "Could not change to /tmp" exit 1 fi # Remainder of script