Bash PATH is not a valid identifier - bash

I'm on a Mac, when I open my shell, it displays the following:
-bash: export: `/Users/jasoncollis/torch/install/bin/torch-activate:/usr/local/bin:/Users/jasoncollis/Library/Enthought/Canopy_64bit/User/bin:/Users/jasoncollis/anaconda/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin': not a valid identifier
This is my #.bash_profile# file:
# Setting PATH for Python 3.5
# The original version is saved in .bash_profile.pysave
PATH=":/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
export PATH
# added by Anaconda3 4.2.0 installer
export PATH=":/Users/jasoncollis/anaconda/bin:$PATH"
# Added by Canopy installer on 2016-11-10
# VIRTUAL_ENV_DISABLE_PROMPT can be set to '' to make the bash prompt show that Canopy is active, otherwise 1
alias activate_canopy="source '/Users/jasoncollis/Library/Enthought/Canopy_64bit/User/bin/activate'"
VIRTUAL_ENV_DISABLE_PROMPT=1 source '/Users/jasoncollis/Library/Enthought/Canopy_64bit/User/bin/activate'
export PATH=":/usr/local/bin:$PATH"
export LC_CTYPE=en_US.UTF-8
export PATH=":/Users/jasoncollis/torch/install/bin/torch-activate:$PATH"
export PATH=":/Users/jasoncollis/torch/install/bin:$PATH"
I've been trying to search for a solution but nothing I've tried has worked so far. Would be really grateful for any help!

Make sure that you edit the right file. For login shells Bash executes .bash_profile and not #.bash_profile#. The later looks like a backup file created by a text editor or script.

Related

Touch, open, ls not working on Mac 10.15.6 terminal, PATH issues

I have been trying to use touch, open and ls commands but this error is returned - -bash: open: command not found. It has always worked until today. This started happening after I added the Postgres path to PATH. Additionally, my PATH looks quite messy and I have absolutely no understanding of that.
Note - I have been through various solutions here on PATH and bash command not found but none seem to be working. Another thing is I can’t use stuff like sudo. I am adding my .bash_profile here if it helps -
# >>> conda initialize >>>
# !! Contents within this block are managed by ‘conda init’ !!
# Setting PATH for Python 3.8
# The original version is saved in .bash_profile.pysave
PATH=“${PATH}”
PATH=/bin:/usr/bin:/sbin:/usr/sbin
export PATH
export PATH = /Users/arif/Library/Python/2.7/bin
export PATH = /Users/arif/Library/Python/2.7/bin:$PATH
echo “source /usr/local/bin/virtualenvwrapper.sh” >> ~/.bash_profilesource /usr/local/bin/virtualenvwrapper.sh
export PATH=/usr/local/opt/ruby/bin:$PATH
# Setting PATH for Python 3.8
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.8/bin:${PATH}"
export PATH
export PATH=/Applications/Postgres.app/Contents/Versions/latest/bin(ScrapProj) Arifs-MacBook-Air:scraper_app arif$ python3
Please help me fix this, Thanks!
the contents of your PATH gets overwritten because the "previous" PATH is not (always) added back when you put a new directory. that is why you end up with just Postgres bin directory at the end and the basic unix tools (ls, touch, etc..) cannot be found.
I tried to fix the issues in your .bash_profile:
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
# these should already be in the PATH, but re-adding them wont hurt...
export PATH="/bin:/usr/bin:/sbin:/usr/sbin:$PATH"
# add other directories to the PATH here remembering to append (previous) PATH at the end
PATH="/Users/arif/Library/Python/2.7/bin:$PATH"
PATH="/usr/local/opt/ruby/bin:$PATH"
PATH="/Library/Frameworks/Python.framework/Versions/3.8/bin:$PATH"
PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH"
echo “source /usr/local/bin/virtualenvwrapper.sh” >> ~/.bash_profilesource /usr/local/bin/virtualenvwrapper.sh

Java_HOME not found when changed shell from Bash to Zsh on OSX?

This is weird, I have set JAVA_HOME for my mac which can be found when I am using bash shell, but if I change shell, I get a message saying JAVA_HOME not set. What could be going on here?
I stumbled upon your question when trying to solve the same issue while migrating from bash to oh-my-zsh. The reason it's not there is that there is no code setting it for zsh but there was for bash. Generally theres something exporting JAVA_HOME whenever a new bash window is opened so it's always set for you. There is a good thread where this might be happening on the Unix & Linux StackExchange site.
To do the same thing in zsh, you can edit the .zshrc which is run every time zsh starts. I found a sample .zshrc which got me most of the way. The key line being:
export JAVA_HOME=`/usr/libexec/java_home`
Here is the file which I appended to the end of my existing ~/.zshrc file:
#zshrc, interactive shell settings
export ZSH=$HOME/.zsh
# emacs integration
[[ $EMACS = t ]] && unsetopt zle
# env
if [[ -e /usr/libexec/java_home ]]; then
export JAVA_HOME=`/usr/libexec/java_home`
fi
if [[ -e /usr/local/lib/node_modules ]]; then
export NODE_PATH=/usr/local/lib/node_modules
fi
# path
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin
export PATH=/opt/usr/sbin:/opt/sbin:/opt/usr/bin:/opt/bin:$PATH
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
export PATH=$HOME/.cabal/bin:$PATH
export PATH=$HOME/.gem/ruby/1.8/bin:$PATH
export PATH=$JAVA_HOME/bin:$PATH
export PATH=$HOME/.bin:$PATH
setopt null_glob
# source all files in zsh root
for include in $ZSH/*.zsh; do
source $include
done
# source all non-controlled files
for include in $ZSH/private/*.zsh; do
source $include
done
unsetopt null_glob
Then source ~/.zshrc to run in the current shell (or just start a new one) and you should be able to see that it is set with export | grep JAVA_HOME.
I also ended up running mkdir ~/.zsh to create the directory this is looking for and removing the .cabal and .gem lines as they were not needed for me.
I have just installed Mac OS Catalina Version 10.15 and found that environment variables such as JAVA_HOME and others that have been set in my .bash_profile :
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH
export ANDROID_HOME=/Users/mynziak/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
export M2_HOME=/usr/local/Cellar/maven/3.6.2/libexec
export M2=${M2_HOME}/bin
export PATH=${PATH}:${M2_HOME}/bin
are not set in fact!
I saw % in terminal instead of general $ that means you are using a zsh shell instead of bash shell. With Catalina zsh is now the default shell and bash will be completely gone in the future.
oh-my-zsh shell:
https://ohmyz.sh/
So you have to setup all environment variables in .zshrc file.
I just copy-pasted every variables from .bash_profile in to .zshrc and re-opened terminal.
Files .bash_profile and .zshrc are hidden (cmd+shift+. - show hidden files in finder) but can be found in path:
/Users/mynziak/.zshrc
but use own username!
When you set JAVA_HOME in a shell, then it is active and available only for that context, and it will be gone when you close that shell.
Instead either change global environment (or) your .bashrc to include it. So that every time you start a shell, the variable will be available.
edit the .profile or .bash_profile to include the JAVA_HOME.
export JAVA_HOME=`/usr/lib....`
and also below command will return the path for java home directory.
/usr/libexec/java_home -v 1.7
where 1.7 is the version you want.
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
export PATH=$JAVA_HOME/bin:$PATH
Add above 2 lines in ~/.bashrc or ~/.zshrc and reload the file using source command.

unable to update path on mac os mavericks

Here is the contents of my .bash_profile
PS1=">>"
alias ls='ls -G'
export CLICOLOR=1
export LSCOLORS=Gxfxcxdxbxegedabagacad
#set SCALA_HOME variable.
export SCALA_HOME=/usr/local/bin/scala
# Added by Canopy installer on 2014-09-22
# VIRTUAL_ENV_DISABLE_PROMPT can be set to '' to make bashprompt show that Canopy is active, otherwise 1
VIRTUAL_ENV_DISABLE_PROMPT=1 source /Users/muralidharn/canopy/bin/activate
#add ipython path to actual PATH variable.
export PATH=$PATH:/Users/muralidharn/canopy/bin
#set JAVA_HOME , this is the way mac recommends that we do it.
#export JAVA_HOME=$(/usr/libexec/java_home)
#add maven to path
export PATH=$PATH:/Users/muralidharn/apache-maven-3.2.3/bin
export PATH=$PATH:/mynewpath
# Added by Canopy installer on 2014-09-22
# VIRTUAL_ENV_DISABLE_PROMPT can be set to '' to make bashprompt show that Canopy is active, otherwise 1
VIRTUAL_ENV_DISABLE_PROMPT=1 source /Users/muralidharn/Library/Enthought/Canopy_64bit/User/bin/activate
My PATH variable is not getting updated with any of the paths that I am exporting. Could someone tell me what I'm doing wrong as I have a feeling its something very silly that I'm just not seeing. I tried restarting the terminal , restarting my computer , source .bash_profile etc... already.
Thanks in advance for your help.
I am not sure if this will work for you, but I would give this syntax a try:
export PATH=\
/usr/local/bin:\
/usr/local/sbin:\
/opt/local/bin:\
/opt/local/sbin:\
$HOME/Dropbox/bin:\
$HOME/bin:\
$HOME/usr:\
/usr/X11/bin:\
/usr/bin:\
/bin:\
/usr/sbin:\
/sbin:\
/Homes/usr/local/bin:\
/vnmr/bin:\
$HOME/Rosetta/main/source/bin
(obviously, use your paths above. This is just an example of how I set mine up).
Also, put this at the top of your bash profile:
#!/bin/bash

-bash: : command not found when launching the shell in Mac OSX

Lately I tried to made some changes to paths in my .bash_profile.
After I tried to validate these changes with source .bash_profile and got -bash: : command not found, I have also noticed that when I open the shell, before the execution of any command, it stands already "-bash: : command not found"...
Obviously, changes made to .bash_profile weren't taken into consideration by the system niether...
Please, help! I guess that I messed with the .bash_profile too much, have no idea how to fix it...
Contents of .bash_profile:
cat .bash_profile
# Finished adapting your PATH environment variable for use with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
##
# MacPorts Installer addition on 2014-03-24_at_12:05:55: adding an appropriate PATH variable for use with MacPorts.
### Your previous /Users/usrname/.bash_profile file was backed up as /Users/usrname/.bash_profile.macports-saved_2014-03-24_at_12:05:55
##export PATH="/Users/usrname/anaconda/bin:$PATH"
# added by Anaconda 1.9.1 installer
##Additional binary folders
export PATH=/Users/usrname/TreeTagger/cmd:$PATH
export PATH= /Users/usrname/TreeTagger/bin:$PATH
export UIMA_HOME= $/Users/usrname/apache-uima
export PATH=$PATH:$UIMA_HOME/bin
export HEIDELTIME_HOME='/Users/usrname/Downloads/heideltime-kit/'
export TREETAGGER_HOME='/Users/usrname/TreeTagger'
source $HEIDELTIME_HOME/metadata/setenv
Updated contents of .bash_profile:
cat .bash_profile
# Finished adapting your PATH environment variable for use with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
##
# MacPorts Installer addition on 2014-03-24_at_12:05:55: adding an appropriate PATH variable for use with MacPorts.
### Your previous /Users/usrname/.bash_profile file was backed up as /Users/usrname/.bash_profile.macports-saved_2014-03-24_at_12:05:55
##export PATH="/Users/usrname/anaconda/bin:$PATH"
# added by Anaconda 1.9.1 installer
##Additional binary folders
export PATH="/Users/usrname/TreeTagger/cmd:$PATH"
export PATH="/Users/usrname/TreeTagger/bin:$PATH"
export UIMA_HOME="/Users/usrname/apache-uima"
export PATH=$PATH:$UIMA_HOME/bin
export HEIDELTIME_HOME="/Users/usrname/Downloads/heideltime-kit/"
export TREETAGGER_HOME="/Users/usrname/TreeTagger"
source $HEIDELTIME_HOME/metadata/setenv
Full shell output after last quotes' correction:
Last login: Thu Jul 31 19:07:05 on ttys000
-bash: : command not found
usr:~ usrname$ cat .bash_profile
# Finished adapting your PATH environment variable for use with MacPorts.
export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
##
# MacPorts Installer addition on 2014-03-24_at_12:05:55: adding an appropriate PATH variable for use with MacPorts.
### Your previous /Users/usrname/.bash_profile file was backed up as /Users/usrname/.bash_profile.macports-saved_2014-03-24_at_12:05:55
##export PATH="/Users/usrname/anaconda/bin:$PATH"
# added by Anaconda 1.9.1 installer
##Additional binary folders
export PATH="/Users/usrname/TreeTagger/cmd:$PATH"
export PATH="/Users/usrname/TreeTagger/bin:$PATH"
export UIMA_HOME="/Users/usrname/apache-uima"
export PATH="$PATH:$UIMA_HOME/bin"
export HEIDELTIME_HOME="/Users/usrname/Downloads/heideltime-kit/"
export TREETAGGER_HOME="/Users/usrname/TreeTagger"
source $HEIDELTIME_HOME/metadata/setenv
usr:~ usrname$ source .bash_profile
-bash: : command not found
Edit with echo commands:
cat .bash_profile
# Finished adapting your PATH environment variable for use with MacPorts.
export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
##
# MacPorts Installer addition on 2014-03-24_at_12:05:55: adding an appropriate PATH variable for use with MacPorts.
### Your previous /Users/usrname/.bash_profile file was backed up as /Users/usrname/.bash_profile.macports-saved_2014-03-24_at_12:05:55
##export PATH="/Users/usrname/anaconda/bin:$PATH"
# added by Anaconda 1.9.1 installer
##Additional binary folders
export PATH="/Users/usrname/TreeTagger/cmd:$PATH"
export PATH="/Users/usrname/TreeTagger/bin:$PATH"
export UIMA_HOME="/Users/usrname/apache-uima"
export PATH="$PATH:$UIMA_HOME/bin"
export HEIDELTIME_HOME="/Users/usrname/Downloads/heideltime-kit/"
export TREETAGGER_HOME="/Users/usrname/TreeTagger"
echo before
source $HEIDELTIME_HOME/metadata/setenv
echo after
usr:~ usrname$ source .bash_profile
-bash: : command not found
usr:~ usrname$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin
Edit +bash version:
echo $BASH_VERSION
3.2.51(1)-release
usr:~ usrname$ source ./.bash_profile
-bash: : command not found
Edit +after set -x was added to .bash_profile:
usr:~ usrname$ source ./.bash_profile
++ $'\016'
-bash: : command not found
++ update_terminal_cwd
++ local 'SEARCH= '
++ local REPLACE=%20
++ local PWD_URL=file://usr.local/Users/usrname
++ printf '\e]7;%s\a' file://usr.local/Users/usrname
This line:
export PATH= /Users/usrname/TreeTagger/bin:$PATH
is the problem. In a variable assignment, including an export, you can't have spaces around the =. With the added space, it sets $PATH to the empty string.
Change it to:
export PATH=/Users/usrname/TreeTagger/bin:$PATH
For safety, you should add double quotes:
export PATH="/Users/usrname/TreeTagger/bin:$PATH"
just in case there are any special characters in the value of $PATH.
You have the same problem with UIMA_HOME.
UPDATE :
Based on later comments, you appear to have a stray control character in your .bash_profile. With set -x it's displayed as $'\016'. bash tries to treat that as a command name, and not surprisingly is unable to find it. Edit your .bash_profile and delete that character.
(The other errors needed to be corrected anyway.)

Adding mahout to path in Ubuntu

I am working in Ubuntu 12.04.
I'm a little unsure on what I've done here. About a month ago I downloaded hadoop from Apache's mirrors and just extracted it into usr/local/hadoop. I also installed mahout via maven, to /opt/mahout.
In .bash_profile I have
export HADOOP_CONF_DIR=$HADOOP_HOME/conf
export MAHOUT_HOME=/opt/mahout/bin
export PATH=$PATH:$MAHOUT_HOME
export HADOOP_HOME=/usr/local/hadoop/bin
and at the bottom of .bashrc I have
# Add Hadoop bin/ directory to PATH
export PATH=$PATH:$HADOOP_HOME/bin
# Add Mahout bin/ directory to PATH
export PATH=$PATH:MAHOUT_HOME/bin
Having done all this, if I opened a new terminal window and typed:
echo $HADOOP_HOME
I would get /usr/local/hadoop
And if I typed
echo $MAHOUT_HOME
a blank line was shown. No text.
So today I went back to .bashrc and noticed that I had, at some point, put this in:
# Set Hadoop-related environment variables
export HADOOP_HOME=/usr/local/hadoop
So underneath that I added
# Set Mahout-related environment variables
export MAHOUT_HOME=/opt/mahout/bin
and low and behold, echo $MAHOUT_HOME now generates opt/mahout/bin in the terminal.
So why do some guides say to add export lines to .bash_profile and others say to add to .bashrc? And why would there have been a blank space instead of an error message?
.bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells.
So generally the first one is sourced whenever you login (or ssh) the computer as a user, while the other is executed everytime you open a terminal like xterm or gnome-terminal.

Resources