Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 01-14-2004, 09:41 AM   #1
LQ Newbie
Registered: Jul 2003
Posts: 7

Rep: Reputation: 0
Bash scripting - add a character to a line.

Occurred to me that I might have stuck this question in the wrong forum, so here it is again.

I use a script to generate a list of files for a backup process. The script find the files then ports the file names to a text file, which the rest of the script uses as a reference for the backup operation. Here is my problem:

The servers I'm backing up are a combination of Windoze and Novhell and both support long file names. When the script reads a long file name or directory with a space in it the file copy fails. I'm guessing that if I add quotation marks to the list of found files it will copy correctly, so the question is this: Can I have a script add quotation marks to the beginning and end of each line in a file? It can be done either as a separate script or, preferably, as part of my current script.

Relevant data:

This is the portion of the script that searches for files:


while read FN; do

The "do" is a bunch of meaningless junk that will make no sense unless you have a DVD library.

A typical SOURCE file looks like this:


A typical "find" output looks like this:


I'd liek the output to look like this:


Any help would be greatly appreciated.

Old 01-14-2004, 10:09 AM   #2
Senior Member
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,823

Rep: Reputation: 120Reputation: 120
Quoting the filenames may not work in all cases. An easy way would be to change your script a bit and set the Internal Field Seperator (IFS) varaible to just include a newline. By default IFS is a newline and whitespace characters like tab and space.

Here is something that should work. Note that there can be no space after the IFS='




for FN in `find $SOURCE_PATH`; do
   # meaningless junk here



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: add date to output line blizunt7 Programming 7 11-10-2004 03:45 AM
end of line character hyperriven Linux - General 1 04-07-2004 08:24 PM
how to avoid new line character gschrade Linux - Newbie 24 02-27-2004 11:14 AM
How do I add character+number to get char in C++? needforspeed Programming 10 02-10-2004 12:16 AM
linux scripting help needed read from file line by line exc commands each line read atokad Programming 4 12-26-2003 10:24 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:17 AM.

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