Correcting path setting in ~/.profile file
No, it's not a syntax error; it's just a letter which is appended after the expansion of $PATH
, because the shell removes quotes...
$ PATH="$HOME/bin:$HOME/.local/bin:$PATH"i
$ echo $PATH
/home/zanna/bin:/home/zanna/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bini
So, as well as prepending local directories, it has effectively removed the existing /snap/bin
from my PATH, and added the non-existent /snap/bini
.
You can remove the i
to repair your PATH.
To see the change, you will need to log out and back in or run source ~/.profile
in any shell you are using (or launch the shell with bash -l
), because .profile
is read by login shells only.
If you did not make this change to your .profile
yourself, you may want to restore the default file by running
mv ~/.profile{,.old}
cp /etc/skel/.profile ~/.profile
This renames the old .profile
.profile.old
(you could also delete the file if you wanted to) and replaces it with the default version for your system from /etc/skel
.
Yes it is a syntax error, the actual .profile
should look like this unless you changed things around (this is the 17.10 version, see notes below it):
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.
# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
This might look different in older versions of Ubuntu where the check if the users bin
directory is present was not included into the .profile
. Eaisiest way to check how it should look like is taking a look at /etc/skel/.profile
.
So to add as you asked in your comment simply place this at the end of your profile file:
# Manual addition for swift development snapshot
export PATH="$PATH:/home/jeremy/swift-4.0-DEVELOPMENT-SNAPSHOT-2017-06-29-a-ubuntu16.04/usr/bin"
If you ever mess up your profile completely, there is a copy where you can get a new one from in /etc/skel/
.
I think here is unclear what the following expression means:
PATH="$HOME/bin:$HOME/.local/bin:$PATH"i
The first part PATH=
means we assign a new value to the (environment) variable $PATH
.
The second part is the new value of that variable. In the current case the variable $HOME
will be expanded with its current value and to that value will be appended the string /bin:
. The same goes for the next part of the string $HOME/.local/bin:
. Finally the current (previous) value of the $PATH
variable will be expanded and appended. The colon :
plays a role of delimiter in the PATH
expression.
The goal is ultimately to write: PATH=<some additional paths>+<the the current value of $PATH>
. We put these additional paths in front of the string, because we want the shell to search for executables first in these locations and only then system wide.
The character i
is unnecessary. It will be appended to the new value of $PATH
and will make a mess, as @Zanna explains in her answer.