Issue
I am working with Oracle E-Business Suite R12 on Oracle Linux 7 environment. For a bash script, I need to read one of the environment variables from the user applmgr as user root.
su applmgr -c 'source /u02/oracle/apps/EBSapps.env run;echo $RUN_BASE;'
The above does echo the RUN_BASE variable. My requirement is to assign environment variable value to a local variable within the script. I tried to the following
BASE_PATH="$(su applmgr -c 'source /u02/oracle/apps/EBSapps.env run;echo $RUN_BASE;)"
That was adding up the .env file printf outputs also. How do I isolate only $RUN_BASE value?
Solution
To exclude all output from the source ...
command before the echo
command in the subshell, redirect its stdout and stderr to /dev/null
:
BASE_PATH=$(su applmgr -c 'source /u02/oracle/apps/EBSapps.env run >/dev/null 2>&1; echo "$RUN_BASE"')
(Side note: the example command in your post had an unclosed single quote, I fixed that too.)
Answered By - janos Answer Checked By - Clifford M. (WPSolving Volunteer)