oracle oraenv script bash I want to do same commande shell CLi into a script

Command shell without script (CLI)

su - oracle
export ORAENV_ASK=NO
export ORACLE_SID=HRPRD
. oraenv
env | grep ora


output:


USER=oracle
**LD_LIBRARY_PATH**=/u01/pe/oracle/u/25/bas/lib
ORACLE_BASE=/u01/pe/oracle
MAIL=/var/spool/mail/oracle
PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/u01/pe/oracle/u/25/bas
PWD=/oracle
HOME=/oracle
LOGNAME=oracle
**ORACLE_HOME**=/u01/pe/oracle/u/25/bas/



My script

rr=`su - oracle`
export ORAENV_ASK=NO
export ORACLE_SID=MySID
uu=`. oraenv`
searchOraHome= `env | grep ora`
echo $searchOraHome


output:


USER=oracle ORACLE_BASE=/u01/app/oracle 
PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/oracle/bin 
MAIL=/var/spool/mail/oracle PWD=/oracle HOME=/oracle LOGNAME=oracle



Why are the variables ORACLE_HOME and LD_LIBRARY_PATH not present with the script shell? 

Is the line:

uu=`. oraenv`


... not correct?
If you us a shell to execute a command in backticks (`), it is executed in a subshell, so all the environment variables it sets are only set in the subshell and are gone when the subshell exits.

You have to "source" the script with

. oraenv


without the backticks.