LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   BASH variables with su - and EOF block (https://www.linuxquestions.org/questions/programming-9/bash-variables-with-su-and-eof-block-4175588014/)

dreamline 08-25-2016 11:47 PM

BASH variables with su - and EOF block
 
Hi all,
I have been programming bash for a while. I'm not a complete expert but I can make my scripts work. However now that I have Linux 7.2 I'm running into problems. Here is mij problem.
I am writing a script with the following block:
Code:

su - oracle << EOF

    examplevar="$(set | grep 'PATH=')
    echo "${examplevar}"
EOF

So within the block I set some variables, however when I want to echo those variables, the are presented as empty. I never had this problem using Oracle Linux 5.x and 6.x. Now that I installed Oracle Linux 7.2 I can't get my scripts to work. The variable is not printed but when I perform the command directly without storing it into a variable, it works perfectly and results in showing the environment variable PATH=.......

Anyone have any idea how to fix this?

Thanks for any help.

Regards,
Dreamline

dreamline 08-26-2016 12:22 AM

Found the solution. I need to escape the $ sign inside an EOF block. :)

Code:

su - oracle << EOF

    examplevar="$(set | grep 'PATH=')
    echo "\${examplevar}"
EOF



All times are GMT -5. The time now is 05:58 AM.