From owner-freebsd-questions Thu Dec 12 1: 9:30 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3E1D937B401 for ; Thu, 12 Dec 2002 01:09:28 -0800 (PST) Received: from smtp.infracaninophile.co.uk (ns0.infracaninophile.co.uk [81.2.69.218]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2DE6943EC5 for ; Thu, 12 Dec 2002 01:09:26 -0800 (PST) (envelope-from m.seaman@infracaninophile.co.uk) Received: from happy-idiot-talk.infracaninophile.co.uk (localhost [IPv6:::1]) by smtp.infracaninophile.co.uk (8.12.6/8.12.6) with ESMTP id gBC99946046842 for ; Thu, 12 Dec 2002 09:09:09 GMT (envelope-from matthew@happy-idiot-talk.infracaninophile.co.uk) Received: (from matthew@localhost) by happy-idiot-talk.infracaninophile.co.uk (8.12.6/8.12.6/Submit) id gBC994B4046841 for freebsd-questions@FreeBSD.ORG; Thu, 12 Dec 2002 09:09:04 GMT Date: Thu, 12 Dec 2002 09:09:04 +0000 From: Matthew Seaman To: FreeBSD Questions Subject: Re: Newline character doesn't work Message-ID: <20021212090904.GA46326@happy-idiot-talk.infracaninophi> Mail-Followup-To: Matthew Seaman , FreeBSD Questions References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.1i X-Spam-Status: No, hits=-2.5 required=5.0 tests=IN_REP_TO,REFERENCES,SPAM_PHRASE_01_02,USER_AGENT, USER_AGENT_MUTT version=2.43 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Thu, Dec 12, 2002 at 07:14:28PM +1100, BSD Freak wrote: > Just tried the following and it doesn't seem to work.. any explanations? > > %echo first line \\n second line > > Output is: > first line \n second line echo is both a shell built-in and a standard command. The standard command doesn't support expanding character escapes like '\n': % /bin/echo "line one\nline two" line one\nline two This is a difference between the BSD echo(1) command and the SYSV equivalent. Of the shells bundled with FreeBSD, /bin/sh uses the standard command version and /bin/tcsh uses a shell built-in that by default has the same behaviour as /bin/echo: % echo $SHELL /bin/tcsh % echo "line one\nline two" line one\nline two However you can set the 'echo_style' shell variable to make the tcsh(1) built-in behave in the SysV style: % set echo_style=sysv % echo "line one\nline two" line one line two Other shells have alternate mechanisms for achieving the same thing, eg: bash(1) uses a '-e' flag to the echo command to enable SysV style bash-2.05b$ echo "line one\nline two" line one\nline two bash-2.05b$ echo -e "line one\nline two" line one line two whereas zsh(1) expands character escapes by default: happy-idiot-talk% echo $ZSH_VERSION 4.0.6 happy-idiot-talk% echo "line one\nline two" line one line two In this case you can use the '-E' flag to make echo behave in the BSD way: % echo -E "line one\nline two" line one\nline two If you want something that will behave consistently independent of whatever shell is being used, try the printf(1) command: % printf "line one\nline two\n" line one line two (Note: no automatic addition of newline after the last character) Cheers, Matthew -- Dr Matthew J Seaman MA, D.Phil. 26 The Paddocks Savill Way Marlow Tel: +44 1628 476614 Bucks., SL7 1TH UK To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message