LinuxQuestions.org
Register a domain and help support LQ
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 10-06-2009, 03:00 AM   #1
HaukeG
LQ Newbie
 
Registered: Oct 2009
Posts: 2

Rep: Reputation: 0
Bash Script combination of sed with pwd command escaping slashes


Hi Everyone,

I do have a little problem with my linux script.

I have one file (wrapper.PLACEHOLDER) with some java wrapper informations. In one spot the absolute java path is needed.
I know that java always is located ../java from the wrapper.PLACEHOLDER file but that can be located anywhere on the filesystem.
I can not use the JAVA_HOME variable (I tried that before).

So my idea was to use the sed command to replace the word PLACEHOLDER inside the wrapper.PLACEHOLDER with the result of 'pwd ../java' command.

The problem is, that the / signs inside the path-string will result in a syntax error.

I tried this command :
Code:
sed "s/PLACEHOLDER/"`pwd ../java/`"/" wrapper.PLACEHOLDER > wrapper.conf
But the result is :
Code:
sed: -e Ausdruck #1, Zeichen 16: unknown option to `s'
(sorry the linux system I am working on is in German)



Does anyone has any ideas?

Best regards and many greetings,
Hauke
 
Old 10-06-2009, 03:28 AM   #2
vonbiber
Member
 
Registered: Apr 2009
Distribution: slackware
Posts: 299

Rep: Reputation: 50
Quote:
Originally Posted by HaukeG View Post

I tried this command :
Code:
sed "s/PLACEHOLDER/"`pwd ../java/`"/" wrapper.PLACEHOLDER > wrapper.conf
But the result is :
Code:
sed: -e Ausdruck #1, Zeichen 16: unknown option to `s'
(sorry the linux system I am working on is in German)

Does anyone has any ideas?
The reason is that
1) your sed delimiter is '/' and you have a '/'
character in your string. Use another delimiter, e.g.,
Code:
sed "s?PLACEHOLDER/"`pwd ../java/`"/" wrapper.PLACEHOLDER > wrapper.conf
2) the string on the right won't be substituted before
sed starts replacing
you should run this 2 lines:
cmd="sed 's?PLACEHOLDER?$(pwd ../java/)?' wrapper.PLACEHOLDER > wrapper.conf"
eval "$cmd"
 
Old 10-06-2009, 05:04 AM   #3
HaukeG
LQ Newbie
 
Registered: Oct 2009
Posts: 2

Original Poster
Rep: Reputation: 0
hey,

thanks for your fast reply. It works. Perfect!

Many greetings,
Hauke
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 script to apply sed command only to a specific text area mauran Programming 6 07-13-2007 05:38 PM
escaping ':' character in bash script paulyche Linux - General 2 11-07-2006 08:18 AM
Bash script - how to add slashes to quotations for sending to MySQL? d60eba Programming 4 07-17-2006 03:16 PM
Bash script - escaping whitespaces colabus Linux - Newbie 15 04-30-2006 12:58 AM
bash and double slashes MD3 Linux - Software 0 02-18-2005 04:13 PM


All times are GMT -5. The time now is 12:26 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration