I'm running Ubuntu20.04 using WSL2, and I'm rather new to linux. While setting up my environment, I messed up my $PATH, as it no longer includes all of the directories in my windows path. Whenever I open Ubuntu, the terminal spews a bunch of errors of this nature:
-bash: export: `Files/Intel/Intel(R)': not a valid identifier
This is one of many errors, one for each component of my windows path. I'm not sure where Windows appends to the linux PATH, so I'm not sure where to look to make the fix.
Edit: Per some of the comments and answers, I do modify the $PATH in my .bashrc, using the code below. Commenting out this code fixes my issue, but I'm not sure what's wrong with this:
function append_to_pathlist
{
# get pathlist into local pathlist (add : at end)
eval "temp_pathlist=\$$1:"
# remove new path from local pathlist if exists
temp_pathlist=${temp_pathlist//"$2:"}
# append new path to front of local pathlist
if [[ "${temp_pathlist}" == ":" ]]; then
temp_pathlist="$2"
else
temp_pathlist="$2:${temp_pathlist}"
fi
# set pathlist to local pathlist (remove : at end)
export $1=${temp_pathlist%":"}
}
# Set the ARCH environment variable
export ARCH="x86_64-ubuntu20_04"
append_to_pathlist PATH "/home/jbrzozo24/.local/bin"
#Add stow pkgs environment variable, and add it to path
export STOW_PKGS_GLOBAL_ROOT="/classes/ece4750/install/stow-pkgs"
export STOW_PKGS_GLOBAL_PREFIX="${STOW_PKGS_GLOBAL_ROOT}/${ARCH}"
append_to_pathlist PATH "${STOW_PKGS_GLOBAL_PREFIX}/bin"
#append_to_pathlist PATH "$/classes/ece4750/install/venv-pkgs/x86_64-ubuntu20_04/python2.7.12/bin"
#PKG CONFIG stu
append_to_pathlist PKG_CONFIG_PATH "${STOW_PKGS_GLOBAL_PREFIX}/share/pkgconfig"
append_to_pathlist PKG_CONFIG_PATH "${STOW_PKGS_GLOBAL_PREFIX}/lib/pkgconfig"
Windows passes environment variables internally when you start a new WSL process as shown in this article.
Probably some profile script is overwriting the initial PATH variable. This documentation explains how to use Win32 variables inside WSL and the options available:
-bash: export: `Files/Intel/Intel(R)': not a valid identifier
Other possibility part of your path variable containing a non-escaped space or especial characters. You can print your path at the beginning of your ~/.bashrc or ~/.profile to see where is the problem.
Related
I am trying to use Python to call a Google Cloud AI platform training API. The path to my service account key JSON file is "/Users/my_mac_username/service_account_key.json", and I added the export statement in the bash_profile file so that it looks like:
# 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 GOOGLE_APPLICATION_CREDENTIALS="/Users/my_mac_username/service_account_key.json"
However, I still got the error:
google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials.
Besides, I have google-cloud-sdk folder installed. I would like to know in which file I should set the environment variable. Thanks for your help!
Assuming your terminal shell is bash, you have your environment variable setup correctly. The new variable will not be available until you reopen the terminal or run source ~/.bash_profile in the current terminal.
If you are running zsh, add the export in your ~/.zshrc file.
To determine which shell you're currently running, use: echo $SHELL from the command line
I have added a path in bashrc, still, the command is not found. When tried in ubuntu it worked but not in WSL. Why this happen?.
export PATH=\wsl$\Ubuntu\usr\local\mbdyn\bin:$PATH
added same path in .bashrc
error: command not found
**Please see the attached image
As you have been told, the forward slash to use is / and if you use the command
PATH="$PATH:/folder/subfolder/"
that value will only last in the PATH for the duration of the session.
To include a value in the PATH permanently, edit the .bashrc file from your home
$ sudo vim ~/.bashrc
you add at the end
export PATH="$PATH:/folder/subfolder/"
you save and you will have that value in the PATH in each session
You will need to modify the PATH variable as follows:
PATH="$PATH:/usr/local/mbdyn/bin"
I understand the code is trying to make the executable in $HOME/.rbenv/bin available in $PATH so it can be executed from the command line but I can't figure out how the code does this. The code is shown below:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> $HOME/.bashrc.
I know that something is being appended to the end of the bashrc file and I know export is used to export environment variables to new shells but I don't see any new shell here. And I have seen echo used in the following way: a = 5; echo $a but I can't figure out why you need it here and what is
PATH="$HOME/.rbenv/bin:$PATH"
doing. what does 'PATH' represent. Is it a variable without the $ and what is 'bin:$PATH'.
In bash (and most other shells) you assign variables without the $, so PATH=something assigns the variable PATH to the string "something".
In Unix/ Linux, PATH is a string variable that contains a list of folders separated by colons (:). For example on my laptop this is my PATH:
> echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
This means that any executable in those folders is accessible anywhere without having to type the full path. You will typically add things to the PATH in your .bashrc file, so they get added when your shell starts up. If you use the which command you can see where a command lives, it will be in one of these folders:
> which rm
/bin/rm
To add a new folder to the PATH, you re-assign PATH to be a string of the new folder, followed by a colon and the previous value of PATH.
In you example, you are adding $HOME/.rbenv/bin to the start of PATH. $HOME will be expanded to your home directory.
To understand this better we can do something like this:
> echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
> export PATH="$HOME/.rbenv/bin:$PATH"
> echo $PATH
/Users/javanut13/.rbenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
As you can see the rbenv folder was added to the front of the PATH variable.
export puts the variable into the environment of the current shell, which means that other commands started in that shell (subprocesses) also get this change. For example if you don't do export and then run a bash script that uses ruby, it will fail because it doesn't have the ~/.rbenv/bin folder in its path.
I'm using a Centos 7 server. I'm entering the command echo $PATH and trying to figure out where it's getting the path that it's putting out. The path doesn't match what's in my .bash_profile, and there is no .bashrc file. How do I find out where my current $PATH is being sourced from?
The Default values for .bashrc and $PATH are stored in files /etc/bashrc and /etc/profile. These files are used by shell and kernel for setting default values for proper functioning of the server.
I would advise not to change any values here, as it might cause abnormal behavior in the server.
My setup is zsh 5.0.5 in arch linux
I have set the PATH variable as below in .zshenv
typeset -U path
path=(~/bin $path)
DW=$HOME/Downloads
but it didn't work. print $PATH shows only
/usr/local/bin:/usr/bin:/usr/bin/vendor_perl:/usr/bin/core_perl
.zshenv was read, because I could see DW variable is set. Only PATH variable isn't set. And what I don't understand is, after rename the .zshenv to .zshrc, PATH variable just works as intended.
Need any special treatment setting environment variables in .zshenv?
I just encountered this problem myself, and the real answer is that Zsh on Arch sources /etc/profile – which overwrites and exports PATH – after having sourced ~/.zshenv.
See: https://wiki.archlinux.org/index.php/Zsh#Configuration_files
It seems that when you have macos or some linux distros there is a canonical solution to the problem which involves /etc/paths or /etc/paths.d. You should be letting /usr/libexec/path_helper construct your path for you using configuration files.
This immediately solved the problem in all places for me.
I've got the same problem. The cause was my .zshrc (fresh install of oh-my-zsh) override PATH (ignoring existing value):
export PATH="/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/core_perl"
To fix, I comment the line.