Terminal: “Invalid Argument: dirname” (El Capitan) I noticed the issue when I first went to run

defaults write com.apple.finder AppleShowAllFiles YES


in OS X Terminal (10.11.2) but this was returned

bash: /usr/bin/defaults: Invalid argument


I'm not sure what is going on with defaults, but I also have a similar issue with brew:

/bin/bash: /usr/bin/dirname: Invalid argument


I clearly broke something (or perhaps malware), but not sure how I did it or when it happened. This is causing all sorts of issues. Any thoughts on fixing it?

My PATH variable looks like this: 

/Users/username/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/MacGPG2/bin:/usr/texbin:/Users/username/.rvm/bin


EDIT:
I noticed my issue is similar to this one: OS X Yosemite Hard Disk Errors even after Repairing them but there's no resolution.
Found a solution! I reinstalled El Capitan from the recovery partition (hold command-R while restarting). The errors are now gone.