I want to append a path in user's PATH variable which should be available in current session.
Background
Numerous persons will run a utility.
Aim is to add the absolute path of the utility the first time it runs so that next runs have the PATH in env & users can directly run the utility without giving the absolute path.
Appended PATH should exist in the user's current session.
Where i got stuck
Shell scripts run as a separate process, hence, variables set there won't be accessible to parent shell.
We can use "." or "source" for the same.
These constructs are different for different shells.
Since the users are quite big chances of them running different shells is quite high.
This fails my run with . or source.
How to determine user's shell
echo $SHELL
This gives the developers shell. I changed my shell to different but the SHELL variable still gives the older shell value.
Hence, unable to determine the shell as well.
Please let me know how to achieve this.
Thanks in advance
Did a quick survey & found users are using all shell's available: bash, ksh, tcsh, ksh, etc
Do i need write for every shell or is there a simpler option available.
Problem sounds very simple but unable to get the solution
Add a variable in user's current session via a shell script.
and also if the user have been exist. you can edit ".bash_profile" in user's home.
[root@*** ~]# cat /home/mysql/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
for u are using BSD , try find / -name "useradd" to find the file.
Consider the scenario where you are providing a utility for general use.
This doesn't entitle you to change the profiles of anybody.
Additionally we have a standard shell, but users customize it based on their preferences.
They start with x, but change it a, b, c, etc.