LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 07-28-2010, 11:40 PM   #1
vikki
Member
 
Registered: Jun 2009
Posts: 30

Rep: Reputation: 18
Shell Script problem with sed


Hello
i have a shell script which will go in some folders using for loop, build some programs with gcc and zip the output.
then i have to paste the file of that zip file into a yml file which will be further used by a ruby watir script.
Code
Quote:
PROJECT_PATH=/uploads/$PROJECT_FOLDER
zip -rq /uploads/$PROJECT_FOLDER/build/Release-iphoneos/Apptitude.app.zip /uploads/$PROJECT_FOLDER/build/Release-iphoneos/Apptitude.app
sed -ie 's|Bundle_Itunes_File_Binary: ""|Bundle_Itunes_File_Binary: "/uploads/$PROJECT_FOLDER/build/Release-iphoneos/Apptitude.app.zip"|g' submit_itunes_app.yml
but when i try to paste the path of zip file into that submit_itunes_app.yml it doesnt work..
it is always replaced by
Bundle_Itunes_File_Binary: "/uploads/$PROJECT_FOLDER/build/Release-iphoneos/Apptitude.app.zip"

Help me where i am going wrong.

also there are some files in this format
Bundle_Itunes_File_Large_1: "image_big121111.png"
nd i want to replace the file name with /path/to/directory/filename

Thanks in advance

Last edited by vikki; 07-28-2010 at 11:41 PM.
 
Old 07-29-2010, 12:34 AM   #2
zirias
Member
 
Registered: Jun 2010
Posts: 361

Rep: Reputation: 59
The shell doesn't subsitute any variables inside single quotes. You have to use double quotes for your sed command if you want that (escaping any double quotes and possibly other problematic characters inside using backslashes)
 
Old 07-29-2010, 12:46 AM   #3
A.Thyssen
Member
 
Registered: May 2006
Location: Brisbane, Australia
Posts: 119

Rep: Reputation: 32
Within single quotes $var substitutions do not happen!

Around the string $PROJECT_FOLDER change it to
'"$PROJECT_FOLDER"'
so that you leave single quotes, enter double quotes, substitute the varaible then return back into single quotes.

the line then becomes

sed -ie 's|Bundle_Itunes_File_Binary: ""|Bundle_Itunes_File_Binary: "/uploads/'"$PROJECT_FOLDER"'/build/Release-iphoneos/Apptitude.app.zip"|g' submit_itunes_app.yml



NOTE you should also have double quotes around your other use of variable assignment to handle spaces and other things...

PROJECT_PATH=/uploads/$PROJECT_FOLDER

should be

PROJECT_PATH="/uploads/$PROJECT_FOLDER"

Similarly in the use of the variable in the zip command.

Not placing variables in quotes is asking for trouble in the future with any input containing white space.

Last edited by A.Thyssen; 07-29-2010 at 12:48 AM.
 
Old 07-29-2010, 12:50 AM   #4
vikki
Member
 
Registered: Jun 2009
Posts: 30

Original Poster
Rep: Reputation: 18
Perfect thanks that worked..
you saved my day..

Now how can i do this in the same file

Bundle_Itunes_File_Large_1: "image_big121111.png"

to

Bundle_Itunes_File_Large_1: "/path/to/directory/image_big121111.png"

for all the files.. as i have dozens of that.. greping each one and changing in all of them one by one will be a pain
 
Old 07-29-2010, 12:58 AM   #5
A.Thyssen
Member
 
Registered: May 2006
Location: Brisbane, Australia
Posts: 119

Rep: Reputation: 32
Dont forget the quotes around all the other uses of variables.

Otherwise when you come to your filenames with spaces in them you will get trouble!!!!
 
  


Reply

Tags
bash, sed


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
sed [shell script] problem cftmon Programming 3 01-09-2010 09:06 PM
shell script, sed nushki Linux - Newbie 1 03-31-2009 01:36 PM
Using sed in a shell script RobHill Linux - General 4 05-29-2007 03:31 PM
problem with sed n variable in shell script dipenchaudhary Programming 4 02-12-2006 10:54 PM
shell script problem on sed. chooi Programming 3 02-10-2006 11:35 PM


All times are GMT -5. The time now is 10:34 AM.

Main Menu
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