4

When I open terminal on my mac it shows

Last login: Sun Mar 15 22:12:02 on ttys000
-bash: “export: command not found
-bash: “export: command not found
-bash: “export: command not found
-bash: “export: command not found

(My echo $PATH)

MacBook-Air-Tim:~ timreznik$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin:/Users/timreznik/bin:/usr/local/bin
MacBook-Air-Tim:~ timreznik$ 

I have already tried to edit my .bash_profile to

# general path munging
PATH=${PATH}:~/bin
PATH=${PATH}:/usr/local/bin

but it still keep showing me “export: command not found when I launch terminal...

P.S. all commands seems to work but my inner perfectionist is screaming!

Tim Reznich
  • 61
  • 1
  • 1
  • 6
  • Do you have a .profile file as well? – Anders Lindén Mar 15 '15 at 20:42
  • Not the actual problem, but still: The tilde `~` is only expanded if it is at the beginning of a shell word, which it is not in `PATH=${PATH}:~/bin`. Rule of thumb: always use `$HOME` instead of `~` when you mean your own HOME. – Jens Mar 15 '15 at 22:01
  • See this question about setting the PATH https://stackoverflow.com/questions/22465332/setting-path-environmental-variables-in-osx-permanently/22465399#22465399 – David W May 14 '16 at 19:49

2 Answers2

10

First, export is a shell builtin:

$ type export
export is a shell builtin

This means that PATH is irrelevant.

Second, the error message makes clear that the script is attempting to run the command “export. There is no such command:

$ “export
bash: $'\342\200\234export': command not found

The solution is to remove the spurious character from before the string export.

This misspelled command is in one of the shell's initialization files. These would include: ~/.bashrc, /etc/bash.bashrc, ~/.bash_profile, ~/.bash_login, ~/.profile, and any files they include.

Alternatively, the following commands will tell you which files and which lines in those files have the misspelled export command:

PS4='+ $BASH_SOURCE:$LINENO:' BASH_XTRACEFD=7 bash -xlic ""  7>trace.out
grep '“export' trace.out

For details on how the above works, see this post.

Community
  • 1
  • 1
John1024
  • 109,961
  • 14
  • 137
  • 171
3

I had a similar problem, the culprit was non-breaking space between export and the name of the variable. To resolve the issue, just replace it with a regular space character.

Details: I had the following in .bash_profile:

export a=foo

When I start new terminal, I would get

-bash: export a=foo: command not found

If we run xxd on the file, however, we can plainly see the problem (dots are non-printable characters:

$ cat .bash_profile | head -n1 | xxd
00000000: 6578 706f 7274 c2a0 613d 666f 6f       export..a=foo

Byte sequence c2a0 stands for non-breaking space

zbstof
  • 1,052
  • 3
  • 14
  • 27