Terminal Crash on Macbook Air 2011, Mavericks I've managed to wreck my Terminal of my Air's OS X (10.9.5) while running a sudo command (sudo mv git /etc/paths.d) during git installation.
(Following https://stackoverflow.com/questions/4725389/how-to-get-started-with-git-on-mac)

Now I receive a continuous string of errors on every new Terminal window that I start, the first 3 lines of which are:

-bash: ???H??: command not found
-bash: command substitution: line 4: syntax error near unexpected token `('
-bash: command substitution: line 4: `:??H?u?H??HH?BH?E??H?? ]?ffff.?:?U??E???



While the Terminal commands do go through after all the errors are listed, RStudio does not start, and the error pop-up states:

"Unexpected exception: Unmatched marking paranthesis ( or (. The error occurred while passing the regular expression fragment: ' "

This error stays even on reinstallation of RStudio (while R works correctly)

I've tried resetting the Terminal by deleting ~/Library/Preferences/com.apple.Terminal.plist but the error still persists.

Really appreciate your help!

--EDIT---

echo $PATH is also gives a string of errors, starting with 
    /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:????:O"::D?M?A??H?
Your PATH variable got contaminated by some irregular file content: either your git file in /etc/paths.d/, /etc/profile or ~/.MacOSX/environment.plist or all three are corrupted.

Use shiftcmdG in Finder to jump to each of the folders and check the content of them.

/etc/paths.d/ should contain a file git with the content /usr/local/git/bin. If you have installed other apps like X11 there may be additional files in paths.d - all containing paths.

The file profile in /etc/ should contain at least

# System-wide .profile for sh(1)

if [ -x /usr/libexec/path_helper ]; then
    eval `/usr/libexec/path_helper -s`
fi

if [ "${BASH-no}" != "no" ]; then
    [ -r /etc/bashrc ] &amp;&amp; . /etc/bashrc
fi


The file environment.plist should look like this:

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
    &lt;key&gt;PATH&lt;/key&gt;
    &lt;string&gt;/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin&lt;/string&gt;
&lt;/dict&gt;
&lt;/plist&gt;


The PATH string may contain other paths as well. The file may contain other keys - depending on other installs you have made previously.



If you have found irregular content in one of the files simply replace it with the content shown above. You have to be an admin to modify the first two files because they are root:wheel realm. If you use TextEdit or another text editor to modify them, be sure to save them as plain text and without file extension (i.e. .txt). You can ignore a missing ~/.MacOSX/environment.plist because it isn't supported in your environment (system version) anymore, besides you use some hacks.