I am running OS X 10.8 on a MBP 2011. I use some bash-scripts for tasks like backups of remote servers. One of the scripts contains this snippet:
#!/bin/bash
if [ "$PWD" != /Users/myuser/Documents/Backup ]
then
echo "Wrong path: $PWD"
exit 0
fi
When I execute this script in /Users/myuser/Documents/Backup
(note the upper case B), I get this response:
Wrong path: /Users/myuser/Documents/backup
For some reason, the $PWD
gets expanded to a lower case name. How can I alleviate this? My filesystem is not case sensitive: both cd Backup
and cd backup
work.
Best Answer
You have two choices really: convert
$PWD
to a consistent case before comparing to your other string (which should also have consistent case). Or drop case-sensitive comparisons.Converting it to lower case before comparing:
Dropping case sensitive comparisons: