Appending a path in user's PATH variable

Hello Folks,

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

OK,could you tell the way you change SHELL.
you can use

env|grep SHELL

to see what the SHELL is.
and use

pstree

to see the tree structure of your SHELL.
for me it's like this

sshdsshdbash
           sshdbashpstree

We are using Free BSD

> echo $SHELL
/bin/tcsh
> bash
$ echo $SHELL
/bin/tcsh

$ env|grep SHELL
SHELL=/bin/tcsh

In all cases it's pinned to tcsh though i am working with bash.

pstree/ptree are not installed.
Doubt if IT will install on a single user's request.

echo $SHELL will always tell the default shell for the user.
to check the current shell, use echo $0

1 Like

Wow, $0 gives the present shell.

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.

U can set a default shell for users by edit "/etc/default/useradd"(CentOS 5.4)

[root@**** ~]#more /etc/default/useradd
# useradd defaults file
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes

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.