Welcome to the Linux Foundation Forum!

How to execute an env file inside EOF block for another user??

kalyangonela
kalyangonela Posts: 1
edited April 2023 in Command Line/Scripting

[oracle@pmyws01 ~]$ cat myOracleDB.env
ORACLE_UNQNAME=myOracleDB_UNQ

[usr@pmyws01 ~]$ cat test.sh
read -p "Enter the database name : " dbname
GLOBAL_VARIABLES(){
export dbname
}
GLOBAL_VARIABLES

sudo su - oracle <<EOF
$(typeset -f GLOBAL_VARIABLES)
GLOBAL_VARIABLES
echo "Database Name is : " ${dbname}
pwd
. ${dbname}.env
echo "Database Unq Name is : " ${ORACLE_UNQNAME}
EOF

[usr@pmyws01 ~]$ sh test.sh
Enter the database name : myOracleDB
Last login: Sun Apr 16 22:58:53 EDT 2023
Database Name is : myOracleDB
/home/oracle
Database Unq Name is :

Categories

Upcoming Training