Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am trying to write a script to access sqlplus and use the output to replace the result in another file. But I am having some issues with it (This script is just a test script and I am just trying to print the updated value.
#!/bin/bash
a=`echo exit|sqlplus -S -L xxx/xxx@xxx @test.sql`
bb=$a
echo a is $a
echo bb is $bb
var=he-llo
echo "goodbye friend" | sed "s/goodbye/$var/"
echo "goodbye friend" | sed "s/goodbye/$bb/"
The output I get is
a is 30-APR-10
bb is 30-APR-10
he-llo friend
sed: -e expression #1, char 10: unterminated `s' command
I am not sure why the last statement alone is not executing. Am I missing something?
I don't think you are missing anything. If I try the example you posted it does work.
Your programming style could be better and could cause problems later on, but that's not the problem in this case. (you need to quote; var='he-llo', bb="$a". single or double, depends on what you want/need. use double for the time being).
Recheck you original script, maybe there is a typo or something else that doesn't belong.
A newline in $a could cause the error message.
Demonstration:-
Code:
a='
30-APR-10' # Set $a containing a newline
bb=$a
echo a is $a
echo bb is $bb
var=he-llo
echo "goodbye friend" | sed "s/goodbye/$var/"
echo "goodbye friend" | sed "s/goodbye/$bb/"
# Gives the same output as your script:-
a is 30-APR-10
bb is 30-APR-10
he-llo friend
sed: -e expression #1, char 10: unterminated `s' command
To remove all newlines in $a try either
bb=${a//$'\n'/}
or
bb=${a//
/}
Thanks druuna for the reply. The script is ugly because its test, once I make it work, I will copy the one to the original script.
Anyways I have tried bb="$a" before, but still I got the same error.
I defined var="he-llo" initially. Just to check I removed the quotes.
Yes, just like I stated in my previous reply. The problem lies elsewhere.
Quote:
Anyways I am running this script only and I still get that error.
Are you still talking about the quoting or is this about the sql file? I assume it is about the quoting, an sqlplus statement cannot produce a sed error.....
One thing I don't get:
In your first post you showed a script and its output. This part a=`echo exit|sqlplus -S -L xxx/xxx@xxx @test.sql` does fill a (a is 30-APR-10).
Does echo exit|sqlplus -S -L xxx/xxx@xxx @test.sql work from the command line (although post #1 does suggest it works)??
its just the newlines and your suggestion worked fine.
druuna,
echo exit|sqlplus -S -L xxx/xxx@xxx @test.sql executed fine, its just that the newlines messed it up. After I did what Kenhelm suggested, it worked. I should have thought of that before.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.