Issue
I want to store my samba binary path to the global $PATH
variable on my rpi4 but it did not work as expected.
I've created a file samba-binary-path.sh
in the folder /etc/profile.sh
and made it with chmod +x
executable.
The file samba-binary-path.sh
contains the following:
export PATH=/usr/local/samba/bin/:/usr/local/samba/sbin/:$PATH
Furthermore I have export PATH=/usr/local/samba/bin/:/usr/local/samba/sbin/:$PATH
also saved in the file /etc/environment
.
Now comes the crazy part. When I execute my script on my cli it work as intended but when it get started from another process the path variable missing my samba binary path.
The affected code block:
#!/bin/bash
BINDIR=$(samba -b | grep 'BINDIR' | grep -v 'SBINDIR' | awk '{print $NF}')
[[ -z $BINDIR ]] && printf "Cannot find the 'samba' binary, is it installed?"
For debbuging purposes I piped the $PATH
variable to /var/log/syslog
.
Here is the result:
- Executed on cli:
$PATH=/usr/local/samba/bin/:/usr/local/samba/sbin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
- Executed from other process:
$PATH=/sbin:/bin:/usr/sbin:/usr/bin
Where do I specify the path so that the samba binary could be always found?
Regards,
Ronny
Solution
How to permanently set $PATH on Raspbian GNU/Linux 10
To explicitly permanently change PATH for all possible environments that do not have PATH
is explicitly set, like a new non-interactive non-login shell that does not inherit PATH
from the parent process, recompile bash with different value of DEFAULT_PATH_VALUE (there's a ./configure
option for it if I remember correctly).
Where do I specify the path so that the samba binary could be always found?
You specify it in your script.
PATH=$PATH:/some/path
# or explicitly
bindir=$(/the/path/to/samba -b ....)
You could also explicitly invoke a login shell when running the script, ergo sourcing /etc/profile*
stuff.
Answered By - KamilCuk