#!/bin/sh
PATH_1=$PATH
echo "PATH_1 is " $PATH_1
function user_func (){
whoami
export PATH=$PATH_1:/usr/local/bin
echo "PATH is" $PATH
exit
}
export -f user_func
su -m hadoop -c 'user_func'
from out put, PATH is not set with PATH_1 append ( it's not another user to run the script, it's the user "hadoop" inside the script to run the function 'user_func' )
PATH_1 is /usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
hadoop
PATH is /bin:/usr/bin
You will see that PATH_1 is not in scope in the function. This is my guess - I do not know much about your environment like OS and shell, or what the other user's .profile or .bashrc may have in it.
That is not what I am saying. You indicated:
1.another user had trouble running the script
2. PATH_1 was apparently not showing up in the output as expected
Answer:
When run by another user the PATH_1 variable was not in scope inside the function.
Has nothing to do with your personal profile settings
there is misunderstanding here
it's not antoher user to run the script, it's another user to run the function
you can check my code "su -m hadoop -c 'user_func' ", hadoop is another user that I mentioned
Okay.
PATH_1 is not being translated as anything, as presented, it is NOT defined in the function because it is not in scope inside the function. I would guess it needs to be exported.