Welcome to WebProNews Breaking eBusiness and Search News
Advertise | Newsletter | Sitemap | News Feeds News Feed 
 WebProNews Search Part of the iEntry network iEntry inc. 

Continuation Lines

A.P. Lawrence
Expert Author
Published: 2006-10-10

WebProNews RSS Feed


There's been a long standing Unix convention of breaking long lines with a "\" to make them easier to read.

You'd almost always see this in files like /etc/printcap, but there are plenty of other places where this convention is used.

A file with continuations might look like this:

This \
is \
one \
line.


and any program reading that is supposed to see it as:

This is one long line.

The "\" is supposed to immediately precede the line feed with no blanks, spaces or anything else between. This rigidity sometimes causes problems when folks use GUI editors to change files; they don't notice the extra spaces and subsequently programs fail.

Bash (and ksh) handle these lines by default. Using the file above as input, we can write a simple script and get one line as output:

$ while read line; do echo $line; done < t
This is one line.
$

If we use "read -r", however, it's different:

$ while read -r line; do echo $line; done < t
This \
is \
one \
line.
$


Adding spaces after each "\" produces something yet again different:

# (spaces added to file)
$ while read line; do echo $line; done < t
This
is
one
line.
$


The missing "\"'s are because now they are simply seen as quoting the spaces. But if you use "read -r" on the same file, it's not seen as quoted:

# (same file, extra spaces after \)
$ while read -r line; do echo $line; done < t
This \
is \
one \
line.


Perl

Given Perl's strong Unix roots, you might think it would recognize this convention also or at least have some funky variable you could set or unset. Nope:

$ cat t.pl
#!/usr/bin/perl
while (<>)
{
print ;
}
# (original file, no spaces after \)
$ ./t.pl < t
This \
is \
one \
line.
$


Section 8.1 of my Perl Cookbook presents an example program that looks for \'s, strips them and gathers full lines.

Apache groks continuation lines, and you can find stuff scattered around for more general cases: Matching line continuation characters.

Interestingly, the Perl debugger does understand backslash continuation: (from "`perldoc perldebug"):

Multiline commands
If you want to enter a multi-line command, such as a subroutine definition with several statements or a format, escape the new-line that would normally end the debugger command with a back-slash. Here's an example:
    DB<1> for (1..4) { \
    cont: print "ok\n"; \
    cont: }
    ok
    ok
    ok
    ok
Note that this business of escaping a newline is specific to interactive commands typed into the debugger.
*Originally published at APLawrence.com

Add to Del.icio.us | Digg | Yahoo! My Web | Furl

Bookmark WebProNews:

View All Articles by A.P. Lawrence



Receive Our Daily Email of Breaking eBusiness News


About the Author:
A.P. Lawrence provides SCO Unix and Linux consulting services http://www.pcunix.com

WebProNews RSS Feed

More Expert Articles Articles

Contact WebProNews
Advertisement





TOP NEWS

Targeted Information for Business
WebProNews is part of the iEntry network

Internet Business: Marketing: Small Business:
WebProNews MarketingNewz SmallBusinessNewz
WebProWorld AdvertisingDay PromoteNews
EcommNewz SalesNewz EntrepreneurNewz

Software: Search Engines: Web Design:
WebMasterFree Jayde B2B DesignNewz
NetworkingFiles SearchZA FlashNewz
SecurityConfig SearchNewz WebSiteNotes

Developer: IT Management: Security:
DevWebPro ITManagement SecurityProNews
DevNewz SysAdminNews SecurityConfig
TheDevWeb NetworkingFiles NetworkNewz

The iEntry Network consists of over 100 web publications reaching millions of Internet Professionals. Contact us to advertise.
eBUSINESS RESOURCES






 Advertise | Contact Us | Corporate | Newsletter | Sitemap | Submit an Article | News Feeds
 WebProNews is an iEntry, Inc. ® publication - $line) { echo $line ; } ?> All Rights Reserved
About WebProNews
WebProNews is the number one source for eBusiness News. Over 5 million eBusiness professionals read WebProNews and other iEntry business and tech publications.

WebProNews provides real-time coverage of internet business.

Free Email Newsletters:
WebProNews SearchNewz
WebProWorld DevWebPro
Marketing SecurityNews
Plus over 100 other newsletters!

Send me relevant info on products and services.


WebProWorld
Ten most recent posts.

NetworkingFiles
Featured Software

WebProNews in the News
View all recent mentions of WebProNews from around the world!

Recent Articles On ...
Google eBusiness
Yahoo Ask Jeeves
MSN Blogs
Search Engines Blogging
Affiliate Programs Marketing
eCommerce Advertising
eBay Sun Microsystems
AOL Adsense
Microsoft Adwords
Oracle IBM
Amazon Apple
SEM Mac
SEO iPod
Adsense XBox
PR Adobe



iEntry.com WebProWorld RSS Feed WebProWorld Contact WebProNews Print Version Email a friend Bookmark us