LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-25-2016, 11:47 PM   #1
dreamline
LQ Newbie
 
Registered: Dec 2010
Posts: 4

Rep: Reputation: 0
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

Last edited by dreamline; 08-25-2016 at 11:50 PM.
 
Old 08-26-2016, 12:22 AM   #2
dreamline
LQ Newbie
 
Registered: Dec 2010
Posts: 4

Original Poster
Rep: Reputation: 0
Found the solution. I need to escape the $ sign inside an EOF block.

Code:
su - oracle << EOF

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


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash to find all placeholder variables in a file and replace will real variables spadez Programming 6 11-26-2013 12:24 PM
Variables and Mkvextract in a bash script and a good resource for bash help? gohmifune Linux - General 9 04-13-2011 08:37 AM
[SOLVED] Bash Scripting Error: EOF encountered in a comment? dilzniksan Programming 4 06-02-2010 11:55 AM
Bash Script: parse active process stderr, strip, dump into variables, use variables TimeFade Programming 1 02-13-2010 06:09 AM
Bash scripting using EOF to exec external programs PB0711 Programming 6 11-04-2009 01:16 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration