From owner-freebsd-questions@FreeBSD.ORG Sun May 30 07:22:41 2010 Return-Path: Delivered-To: questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 248A81065672 for ; Sun, 30 May 2010 07:22:41 +0000 (UTC) (envelope-from m.seaman@infracaninophile.co.uk) Received: from smtp.infracaninophile.co.uk (gate6.infracaninophile.co.uk [IPv6:2001:8b0:151:1::1]) by mx1.freebsd.org (Postfix) with ESMTP id 60D548FC08 for ; Sun, 30 May 2010 07:22:40 +0000 (UTC) Received: from seedling.black-earth.co.uk (seedling.black-earth.co.uk [81.187.76.163]) (authenticated bits=0) by smtp.infracaninophile.co.uk (8.14.4/8.14.4) with ESMTP id o4U7MSWd027810 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Sun, 30 May 2010 08:22:28 +0100 (BST) (envelope-from m.seaman@infracaninophile.co.uk) Message-ID: <4C021234.3000803@infracaninophile.co.uk> Date: Sun, 30 May 2010 08:22:28 +0100 From: Matthew Seaman Organization: Infracaninophile User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.9) Gecko/20100317 Thunderbird/3.0.4 MIME-Version: 1.0 To: Aiza References: <4C01F419.10100@comclark.com> <20100530053935.GG8866@dan.emsphone.com> <4C02015C.5070605@comclark.com> <20100530131730.1931dbd4@icy.localdomain> <4C020CB2.5070408@comclark.com> In-Reply-To: <4C020CB2.5070408@comclark.com> X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Virus-Scanned: clamav-milter 0.96.1 at lucid-nonsense.infracaninophile.co.uk X-Virus-Status: Clean X-Spam-Status: No, score=2.0 required=5.0 tests=DKIM_ADSP_ALL,SPF_FAIL autolearn=no version=3.3.1 X-Spam-Level: ** X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on lucid-nonsense.infracaninophile.co.uk Cc: Anh Ky Huynh , "questions@freebsd.org" Subject: Re: sh script writing help X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 30 May 2010 07:22:41 -0000 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 30/05/2010 07:58:58, Aiza wrote: > Anh Ky Huynh wrote: >> On Sun, 30 May 2010 14:10:36 +0800 >> Aiza wrote: >> >>> Dan Nelson wrote: >>>> In the last episode (May 30), Aiza said: >>>>> In a .sh type script I have && exerr " very long message gt 250 >>>>> char" all on the same line. This is a real pain to edit. >>>>> >>>>> Is there some code a can use to continue this on the next line >>>>> so I can see it on the screen and still have the command >>>>> function? I tried \ with no luck. >>>> \ should work just fine: >>>> >>>> $ echo "long line \ >>>> split onto two" >>>> long line split onto two >>>> $ >>>> >>> >>> You example works only because the continuation starts at position >>> 1. >>> >>> $ [ -n "${test-name-fowarding}" -o -n "${test-noname}" ] || \ >>> exerr "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\ >>> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" >>> this is for ease of reading the code but will display with a bunch >>> of spaces in the middle of the sentence. The \ works fine bypassing >>> all white space between code not so for white space between the " >>> ". >>> >>> Is there a coding method to get around this? >> >> Do you try to read your expression from a file? >> exerr `cat /path/to/data` >> >> the contents of /path/to/data are your very long string. A standard means of doing this sort of thing is to use a 'Here' document: if ! [ -n "${test-name-forwarding}" -o -n "${test-noname}" ]; then exerr <<-E_O_EXERR xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx E_O_EXER fi The '<<-' operator is a variant on the usual '<<' operator used for this: the only difference is that it strips leading tabs from the lines in the here document. Cheers, Matthew - -- Dr Matthew J Seaman MA, D.Phil. 7 Priory Courtyard Flat 3 PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate JID: matthew@infracaninophile.co.uk Kent, CT11 9PW -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.14 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkwCEjQACgkQ8Mjk52CukIzc7gCbBalo5oJcsw+jkXHOm4+8qU3f l2EAn30WwaSL3kTZ1iy3FGkTxQlBZ3pr =WxjG -----END PGP SIGNATURE-----