Exporting $PATH and editing .profile

sossego

Retired from the forums

Reaction score: 147
Messages: 1,557

Code:
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
Code:
 echo $PATH && cat .profile|grep PATH
is invoked.

Code:
# $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

Active Member

Reaction score: 23
Messages: 189

sossego said:
Code:
export $PATH=PATH:/path/to/variable

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

To "reload" .profile use this:
Code:
# . ~/.profile
 

Michael_S

New Member


Messages: 13

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

To "reload" .profile use this:
Code:
# . ~/.profile
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

Daemon

Reaction score: 579
Messages: 1,058

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).
 

Michael_S

New Member


Messages: 13

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
Code:
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

Daemon

Reaction score: 579
Messages: 1,058

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

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 11,600
Messages: 37,926

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:
Code:
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).
Code:
# 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).
 

Michael_S

New Member


Messages: 13

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:

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

Administrator
Staff member
Administrator
Moderator

Reaction score: 11,600
Messages: 37,926

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.
 

Michael_S

New Member


Messages: 13

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.
Hi, thanks for the reply. But that line is comment off in ~/.profile

Code:
# PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:$HOME/bin:$HOME/julia-1.6.1/bin; export PATH
Code:
$ 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

Administrator
Staff member
Administrator
Moderator

Reaction score: 11,600
Messages: 37,926

But that line is comment off in ~/.profile
Then uncomment it.

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?

Code:
   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:
Code:
export PATH="$PATH:$HOME/julia-1.6.1/bin"
 

Michael_S

New Member


Messages: 13

Then uncomment it.


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

Code:
   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:
Code:
export PATH="$PATH:$HOME/julia-1.6.1/bin"
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

Administrator
Staff member
Administrator
Moderator

Reaction score: 11,600
Messages: 37,926

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.
Also adding the line to ~/.shrc does not work either.
Did you add it as I showed? Then run echo $PATH to check.
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

Daemon

Reaction score: 788
Messages: 1,626

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
Code:
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.
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 11,600
Messages: 37,926

Code:
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)'.
 
Top