Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 07-29-2010, 12:40 AM   #1
Registered: Jun 2009
Posts: 30

Rep: Reputation: 18
Shell Script problem with sed

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.
zip -rq /uploads/$PROJECT_FOLDER/build/Release-iphoneos/ /uploads/$PROJECT_FOLDER/build/Release-iphoneos/
sed -ie 's|Bundle_Itunes_File_Binary: ""|Bundle_Itunes_File_Binary: "/uploads/$PROJECT_FOLDER/build/Release-iphoneos/"|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/"

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-29-2010 at 12:41 AM.
Old 07-29-2010, 01:34 AM   #2
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, 01:46 AM   #3
Registered: May 2006
Location: Brisbane, Australia
Posts: 120

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

Around the string $PROJECT_FOLDER change it to
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/"|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...


should be


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 01:48 AM.
Old 07-29-2010, 01:50 AM   #4
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"


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, 01:58 AM   #5
Registered: May 2006
Location: Brisbane, Australia
Posts: 120

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!!!!


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

All times are GMT -5. The time now is 07:31 PM.

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