# Exporting $PATH and editing .profile



## sossego (Feb 2, 2014)

```
export $PATH=PATH:/path/to/variable
```
When doing the above in /$USER_HOME/.profile, the changes are not immediate nor do other open terminals show the change when 

```
echo $PATH && cat .profile|grep PATH
```
 is invoked.


```
# $FreeBSD: stable/10/share/skel/dot.profile 199243 2009-11-13 05:54:55Z ed $
#
# .profile - Bourne Shell startup script for login shells
#
# see also sh(1), environ(7).
#

# remove /usr/games if you want
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/usr/local/bin/python:/usr/local/bin/perl:/usr/home/raspycat/depot_tools:$HOME/bin; export PATH

# Setting TERM is normally done through /etc/ttys.  Do only override
# if you're sure that you'll never log in via telnet or xterm or a
# serial line.
# TERM=xterm; 	export TERM

BLOCKSIZE=K;	export BLOCKSIZE
EDITOR=vi;   	export EDITOR
PAGER=more;  	export PAGER

# set ENV to a file invoked each time sh is started for interactive use.
ENV=$HOME/.shrc; export ENV

if [ -x /usr/games/fortune ] ; then /usr/games/fortune freebsd-tips ; fi
```


----------



## worldi (Feb 2, 2014)

sossego said:
			
		

> ```
> export $PATH=PATH:/path/to/variable
> ```



The dollar sign is in the wrong place:

```
export PATH="$PATH:/yet/another/directory"
```

To "reload" .profile use this:

```
# . ~/.profile
```


----------



## Schroter (May 2, 2021)

worldi said:


> The dollar sign is in the wrong place:
> 
> ```
> export PATH="$PATH:/yet/another/directory"
> ...


Hi Thanks, This method works but, only for the current terminal session. Once close terminal. Then start terminal and run again (in my case julia), I get `sh: julia: not found`

Thanks & Best Rergards
Michael


----------



## mark_j (May 2, 2021)

You need to place the extra path extension in a permanent, read-at-login file, which depends on your shell: .cshrc/.tcshrc, .zshrc, .bashrc etc. Some  shells read .profile (zsh if invoked as sh,  sh, bash for example).


----------



## Schroter (May 3, 2021)

mark_j said:


> You need to place the extra path extension in a permanent, read-at-login file, which depends on your shell: .cshrc/.tcshrc, .zshrc, .bashrc etc. Some  shells read .profile (zsh if invoked as sh,  sh, bash for example).


Hi, thanks for the reply. My user shell is _sh_ root shell is _csh_. I tried adding the line

```
export PATH="$PATH:/home/michael/julia-1.6.1/bin"
```
 to _~/.shrc_ and _~/.cshrc_ files and restarted the terminal. In both cases it gave me the error command not found.

I did the same to _~/.profile_ (sh) but the result is the same. Please refer this link.

Would anyone be please able to help me in this regards?

Thanks & Best Regards

Michael


----------



## mark_j (May 3, 2021)

No double qoute marks required.
If you're using sh then .profile will suffice. Logout then login.


----------



## SirDice (May 3, 2021)

Michael_S said:


> to _~/.shrc_ and _~/.cshrc_ files


The export(1) is the wrong syntax for a C shell, thus it will not work in a ~/.cshrc. If you read ~/.cshrc you'll see the path is already set, just add your directory to the list:

```
set path = (/sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin $HOME/bin $HOME/julia-1.6.1/bin)
```

The ~/.shrc is only read by sh(1) if ENV is set (it's not set by default on FreeBSD). 

```
# This file will be used if the shell is invoked for interactive use and
# the environment variable ENV is set to this file.
```

So for sh(1) and bash(1) just use ~/.profile. For csh(1) and tcsh(1) use ~/.cshrc. Note that either of these files are only read when it's an interactive shell and they're read when you login or when starting a _new_ interactive shell. They do NOT retroactively change variables inside existing shells (that's not how variable inheritance works).


----------



## Schroter (May 3, 2021)

mark_j said:


> No double qoute marks required.
> If you're using sh then .profile will suffice. Logout then login.


Hi Mark it does not work please refer the below code:


```
$ echo $SHELL
/bin/sh
$ edit .profile
^[ (escape) menu ^y search prompt ^k delete line   ^p prev li     ^g prev page
^o ascii code    ^x search        ^l undelete line ^n next li     ^v next page
^u end of file   ^a begin of line ^w delete word   ^b back 1 char ^z next word
^t top of text   ^e end of line   ^r restore word  ^f forward char
^c command       ^d delete                                      ESC-Enter: exit
=====line 34 col 0 lines fr                         ===========================
PAGER=less;     export PAGER

# $FreeBSD$
#
# .profile - Bourne Shell startup script for login shells
#
# see also sh(1), environ(7).
#

# These are normally set through /etc/login.conf.  You may override them here
# if wanted.
# PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:$HOME/bin; export PATH

# Setting TERM is normally done through /etc/ttys.  Do only override
# if you're sure that you'll never log in via telnet or xterm or a
# serial line.
# TERM=xterm;   export TERM

EDITOR=vi;      export EDITOR
PAGER=less;     export PAGER

# set ENV to a file invoked each time sh is started for interactive use.
ENV=$HOME/.shrc; export ENV

# Let sh(1) know it's at home, despite /home being a symlink.
if [ "$PWD" != "$HOME" ] && [ "$PWD" -ef "$HOME" ] ; then cd ; fi

# Query terminal size; useful for serial lines.
if [ -x /usr/bin/resizewin ] ; then /usr/bin/resizewin -z ; fi

# Display a random cookie on each login.
if [ -x /usr/bin/fortune ] ; then /usr/bin/fortune freebsd-tips ; fi


##################################################
export PATH=$PATH:/home/michael/julia-1.6.1/bin

#Close terminal and open and run:

$ julia
sh: julia: not found
$ julia-1.6.1
sh: julia-1.6.1: not found

#But the below command always work

$ ./julia-1.6.1/bin/julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.6.1 (2021-04-23)
_/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia>
```

Please let me know your opinion please.

Thanks & Best Regards

Michael


----------



## SirDice (May 3, 2021)

Look at the variable itself, just enter `echo $PATH`. Then you can easily tell if it's set correctly or not.

And all the way at the top of ~/.profile PATH is already being set, just add your directory to that line.


----------



## Schroter (May 3, 2021)

SirDice said:


> SirDice said:
> 
> 
> > Look at the variable itself, just enter `echo $PATH`. Then you can easily tell if it's set correctly or not.
> ...


Hi, thanks for the reply. But that line is comment off in ~/.profile


```
# PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:$HOME/bin:$HOME/julia-1.6.1/bin; export PATH
```


```
$ echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin
```

even though I add it and close the terminal and open and run $ julia I still get the error.

Thanks & Best Regards
Michael


----------



## SirDice (May 3, 2021)

Michael_S said:


> But that line is comment off in ~/.profile


Then uncomment it.



Michael_S said:


> even though I add it and close the terminal and open


I suspect your terminal isn't a login shell. Does the fortune(1) get printed when you open a terminal?


```
Invocation
     If no arguments are present and if the standard input of the shell is
     connected to a terminal (or if the -i option is set), the shell is
     considered an interactive shell.  An interactive shell generally prompts
     before each command and handles programming and command errors
     differently (as described below).  When first starting, the shell
     inspects argument 0, and if it begins with a dash (‘-’), the shell is
     also considered a login shell.  This is normally done automatically by
     the system when the user first logs in.  A login shell first reads
     commands from the files /etc/profile and then .profile in a user's home
     directory, if they exist.  If the environment variable ENV is set on
     entry to a shell, or is set in the .profile of a login shell, the shell
     then subjects its value to parameter expansion and arithmetic expansion
     and reads commands from the named file.  Therefore, a user should place
     commands that are to be executed only at login time in the .profile file,
     and commands that are executed for every shell inside the ENV file.  The
     user can set the ENV variable to some file by placing the following line
     in the file .profile in the home directory, substituting for .shrc the
     filename desired:

           ENV=$HOME/.shrc; export ENV

     The first non-option argument specified on the command line will be
     treated as the name of a file from which to read commands (a shell
     script), and the remaining arguments are set as the positional parameters
     of the shell ($1, $2, etc.).  Otherwise, the shell reads commands from
     its standard input.
```

Looking a little further, it looks like the standard ~/.profile sets ENV. As you have sh(1) set as your shell it should be treated as a login shell. I normally don't use sh(1) interactively, only for scripting, and those startup scripts always drive me nuts. Depending on how the shell is started it will run ~/.profile _or_ ~/.shrc and I always mess those up. In your case leave ~/.profile as-is, there's no need to change it (you can find a "clean" copy in /usr/share/skel if you messed it up). 
Just create a ~/.shrc:

```
export PATH="$PATH:$HOME/julia-1.6.1/bin"
```


----------



## Schroter (May 3, 2021)

SirDice said:


> Then uncomment it.
> 
> 
> I suspect your terminal isn't a login shell. Does the fortune(1) get printed when you open a terminal?
> ...


Hi, thanks for reply. nothing happens when I start terminal just $ sign. Also adding the line to ~/.shrc does not work either. Might change the (user) shell to csh. I did the same to it as root as well.
Thanks & Best Regards
Michael


----------



## SirDice (May 3, 2021)

Michael_S said:


> nothing happens when I start terminal just $ sign.


That's a sign it's not a login shell as ~/.profile would get executed when it is. 


Michael_S said:


> Also adding the line to ~/.shrc does not work either.


Did you add it as I showed? Then run `echo $PATH` to check. 


Michael_S said:


> Might change the (user) shell to csh.


Use tcsh(1) for your user account, it has a number of extra features csh(1) doesn't have. Both use ~/.cshrc, so change that file if you want to use the C shells.


----------



## T-Daemon (May 3, 2021)

Instead of tinkering with every shells different configuration file assign the `PATH` environment using the 'login classes method', which makes it valid for every possible shell. See login.conf(5).

Delete the `PATH` environment settings in the shells configuration files, edit  ~/.login_conf

```
me:\
   :path=/sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin ~/bin ~/julia-1.6.1/bin:
```

Afterwards run `cap_mkdb ./login_conf` , log out, log in.


----------



## grahamperrin@ (Jun 10, 2021)

SirDice said:


> Use tcsh(1) for your user account, it has a number of extra features csh(1) doesn't have.



The link for the latter leads to the manual page for the former (no surprise there), https://man.freebsd.org/tcsh(1)#NEW_FEATURES_(_) mentions time-stamping of history but I find stamps with csh (as well as tcsh). 

If not the manual page, is there a better place to learn of the differences?


----------



## SirDice (Jun 10, 2021)

```
Throughout
       this  manual, features of tcsh not found	in most	csh(1) implementations
       (specifically, the 4.4BSD csh) are labeled  with	 `(+)',	 and  features
       which are present in csh(1) but not usually documented are labeled with
       `(u)'.
```


----------



## ziomario (Thursday at 3:03 PM)

SirDice said:


> For csh(1) and tcsh(1) use ~/.cshrc.



I'm using *csh* and I've explored the conf. file that you have suggested,called "*/home/marietto/.cshrc*",but it told me :



> # These are normally set through /etc/login.conf.  You may override them here if wanted"



So,I have edited the file called /etc/login.conf and I've added the new path called /compat/linux/home/marietto/Desktop below the word `default`. I hope this is correct.


```
default:\
    :path=/compat/linux/home/marietto/Desktop /sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin ~/bin:\
```


----------



## SirDice (Thursday at 3:12 PM)

login.conf is fine if you want to set it system-wide and independent of the user's shell. Don't forget to update the database after editing login.conf.


----------



## ziomario (Thursday at 3:14 PM)

SirDice said:


> login.conf is fine if you want to set it system-wide and independent of the user's shell. Don't forget to update the database after editing login.conf.



how can I update the database ? I thought that was enough to reboot.


----------



## Phishfry (Thursday at 3:32 PM)

ziomario said:


> how can I update the database ? I thought that was enough to reboot.





T-Daemon said:


> Afterwards run `cap_mkdb ./login_conf` , log out, log in.








						cap_mkdb(1)
					






					www.freebsd.org


----------



## ziomario (Thursday at 3:39 PM)

```
# cap_mkdb /etc/login.conf
```
ok.


----------



## Phishfry (Thursday at 3:41 PM)

Chapter 14. Security
					

FreeBSD is an operating system used to power modern servers, desktops, and embedded platforms.




					www.freebsdhandbook.com


----------



## Erichans (Thursday at 3:44 PM)

ziomario said:


> how can I update the database ? I thought that was enough to reboot.


The answer is in the man page; login.conf(5):

```
DESCRIPTION
[...]
     The default /etc/login.conf shipped with FreeBSD is an out	of the box
     configuration.  Whenever changes to this, or the user's ~/.login_conf,
     file are made, the	modifications will not be picked up until cap_mkdb(1)
     is	used to	compile	the file into a	database.
```
Just use `cap_mkdb` with the conf file you just edited.


----------



## ziomario (Thursday at 3:46 PM)

Reload the page.


----------

