# Command only found with -su



## RogellParadox (Aug 19, 2021)

I was installing Julia in my fresh FreeBSD installation. I set the path at 
	
	



```
~/.cshrc
```
 and finally entered 
	
	



```
source ~/.cshrc.
```

The thing is: when I type "julia", terminal doesn't find it:

```
$ julia
sh: julia: not found
```

But when I do the same command with su, it works.
I tried checking the $PATH variables and I came along something interesting:


```
$ echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin
$ su
Password:
root@Leon:/home/leon # echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin:/usr/local/bin/julia-1.6.2/bin
root@Leon:/home/leon #
```

Seems like there are two $PATH files, one for super user, the other for general user? How can I change that?


----------



## SirDice (Aug 19, 2021)

RogellParadox said:


> How can I change that?


Path is set in .shrc (for sh(1)) or .cshrc for tcsh(1) (root's shell is csh(1)). Your user's shell is set to sh(1).


----------



## T-Daemon (Aug 19, 2021)

To make $PATH `.../julia-1.6.2/bin` valid for all shells, without taking every shells configuration file in account, use the "login class method" to set the environment variable. Set it system wide in /etc/login.conf:

```
default:\
    ...
    :path=/sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin /usr/local/bin/julia-1.6.2/bin ~/bin:\
    ...
```

or per user base in ~/.login_conf:

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

Run `cap_mkdb /etc/login.conf` (or `cap_mkdb ~/login_conf`) afterwards. If user is logged in, log out, log in to take effect.


----------



## RogellParadox (Aug 19, 2021)

SirDice said:


> Path is set in .shrc (for sh(1)) or .cshrc for tcsh(1) (root's shell is csh(1)). Your user's shell is set to sh(1).



I don't see any of those paths in 
	
	



```
/.shrc
```


```
# $FreeBSD$
#
# .shrc - bourne shell startup file
#
# This file will be used if the shell is invoked for interactive use and
# the environment variable ENV is set to this file.
#
# see also sh(1), environ(7).
#


# file permissions: rwxr-xr-x
#
# umask 022

# Uncomment this to enable the builtin vi(1) command line editor in sh(1),
# e.g. ESC to go into visual mode.
# set -o vi



^G Ajuda     ^O Gravar    ^W Onde está?^K Recortar  ^T Executar  ^C Local
^X Sair      ^R Ler o arq ^\ Substituir^U Colar     ^J Justificar^/ Ir p/ linha
  GNU nano 5.8                         /home/leon/.shrc                                     
# $FreeBSD$
#
# .shrc - bourne shell startup file
#
# This file will be used if the shell is invoked for interactive use and
# the environment variable ENV is set to this file.
#
# see also sh(1), environ(7).
#


# file permissions: rwxr-xr-x
#
# umask 022

# Uncomment this to enable the builtin vi(1) command line editor in sh(1),
# e.g. ESC to go into visual mode.
# set -o vi


# some useful aliases
alias h='fc -l'
alias j=jobs
  GNU nano 5.8                   /home/leon/.shrc                               
# some useful aliases
alias h='fc -l'
alias j=jobs
alias m="$PAGER"
alias ll='ls -laFo'
alias l='ls -l'
alias g='egrep -i'

# # be paranoid
# alias cp='cp -ip'
# alias mv='mv -i'
# alias rm='rm -i'


# set prompt: ``username@hostname:directory $ ''
PS1="\u@\h:\w \\$ "

# search path for cd(1)
# CDPATH=:$HOME
```




T-Daemon said:


> To make $PATH `.../julia-1.6.2/bin` valid for all shells, without taking every shells configuration file in account, use the "login class method" to set the environment variable. Set it system wide in /etc/login.conf:
> 
> ```
> default:\
> ...



Tried with both. Nothing changes.


----------



## T-Daemon (Aug 19, 2021)

RogellParadox said:


> Tried with both. Nothing changes.


No problem here:

```
test@s840:~ $ grep -m 1 path /etc/login.conf
:path=/sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin /usr/local/bin/julia-1.6.2/bin ~/bin:\

test@s840:~ $ echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/local/bin/julia-1.6.2/bin:/home/test/bin

test@s840:~ $ echo $SHELL
/bin/sh

test@s840:~ $ chsh -s /bin/tcsh
Password:
test@s840:~ $ exit
login:

test@s840:~ % echo $SHELL
/bin/tcsh

test@s840:~ % echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/local/bin/julia-1.6.2/bin:/home/test/bin
```

Please make sure to remove all $PATH variables in any shell configuration files, run cap_mkdb(1), to take effect of the variable change, log the user out and in.


----------



## RogellParadox (Aug 19, 2021)

T-Daemon said:


> No problem here:
> 
> ```
> test@s840:~ $ grep -m 1 path /etc/login.conf
> ...



Did everything as suggested, shell did change, but path still the same.


```
leon@Leon:~ % echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin
```

I noticed there's this _/usr/games _path and as far as I looked for, didn't find it in *any* of those config files (_~/.profile_, _~/.shrc, ~/.cshrc, .login_conf_)_, _what makes me think there could be probably _another_ conf file?


----------



## SirDice (Aug 20, 2021)

RogellParadox said:


> what makes me think there could be probably _another_ conf file?


You might have an older /etc/login.conf. That /usr/games directory was removed a really long time ago. What version of FreeBSD did you install?

Edit: 6 years ago: https://svnweb.freebsd.org/base/head/etc/login.conf?r1=278616&r2=278615&pathrev=278616


----------



## T-Daemon (Aug 20, 2021)

RogellParadox said:


> Did everything as suggested, shell did change, but path still the same.


Please post entire /etc/login.conf. I assume you have run `cap_mkdb /etc/login.conf` after edit.



RogellParadox said:


> I noticed there's this _/usr/games _path ...


As SirDice asked, what version of FreeBSD are you running? Please post `uname -a`.

Also


RogellParadox said:


> The thing is: when I type "julia", terminal doesn't find it:
> ...
> But when I do the same command with su, it works.
> ...
> ...


Have you set 'julia' path for 'root' in /root/.cshrc?


----------



## Vull (Aug 20, 2021)

RogellParadox said:


> I was installing Julia in my fresh FreeBSD installation. I set the path at
> 
> 
> 
> ...


You should not be able to invoke `source ~/.cshrc` (or `source ~/.cshrc.`) from a /bin/sh shell prompt, _*at all*_:
	
	



```
len@mate:~ $ source ~/.cshrc
sh: source: not found
len@mate:~ $ source ~/.cshrc.
sh: source: not found
```

The `source` command is implemented by the csh shell as an internal, "builtin" command, however, it is _not_ implemented internally by the sh shell. Reference: `man builtin` (or `man source`).

Note particularly that it says:
    "If a command specified to the shell contains a slash ‘/’, the shell will
     not execute a builtin command, even if the last component of the
     specified command matches the name of a builtin command.  Thus, while
     specifying “echo” causes a builtin command to be executed under shells
     that support the echo builtin command, specifying “/bin/echo” or “./echo”
     does not."

Furthermore, there is no _external_ `source` program or script _either_, or, none that I can readily find in FreeBSD-13.0-RELEASE:
	
	



```
len@mate:~ $ which source
len@mate:~ $ su
Password:
root@mate:/home/len # which source
source: shell built-in command.
root@mate:/home/len #
```

In addition, when you invoke `~/.cshrc` the command is executed in a subshell. If a command is executed in a subshell, changes in environment variables will not be retained when the instruction pointer returns to the invoking shell.

To work around this problem, you can run a command in the main shell instead of in a subshell, and thereby retain environment variables, by using the "dot" command syntax, to wit:

`. ~/.cshrc`

instead of

`~/.cshrc`

However, _this_ leads to the further problem that csh commands are not usable by the sh shell:
	
	



```
len@mate:~ $ . ~/.cshrc
alias: history: not found
alias: 25: not found
h='fc -l'
alias: jobs: not found
alias: -l: not found
j=jobs
alias: la: not found
alias: ls: not found
alias: -aF: not found
alias: lf: not found
alias: ls: not found
alias: -FA: not found
alias: ls: not found
alias: -lAF: not found
ll='ls -laFo'
/home/len/.cshrc: setenv: not found
/home/len/.cshrc: setenv: not found
/home/len/.cshrc: 31: Syntax error: "(" unexpected (expecting "fi")
len@mate:~ $
```
In summary, this post doesn't make much sense at all, unless you're using something other than FreeBSD 13.0...?

Edited to add:
^"Seems like there are two $PATH files, one for super user, the other for general user? How can I change that?"

You can't. Super user is using /root/.cshrc and general user is using /home/leon/.shrc. PATH is set in /etc/login.conf as outlined above by T-Daemon, but can be overridden in .cshrc for csch shells, or in .shrc for sh shells. Normally this is done (for sh shells) by a statement like:

`PATH=$PATH:/usr/local/bin/julia-1.6.2/bin`

I'm not sure of the syntax for csh shells.


----------

