From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20468 invoked from network); 24 Oct 2005 00:30:56 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 24 Oct 2005 00:30:56 -0000 Received: (qmail 54953 invoked from network); 24 Oct 2005 00:30:46 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 24 Oct 2005 00:30:46 -0000 Received: (qmail 6787 invoked by alias); 24 Oct 2005 00:30:39 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 9545 Received: (qmail 6777 invoked from network); 24 Oct 2005 00:30:39 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 24 Oct 2005 00:30:39 -0000 Received: (qmail 54014 invoked from network); 24 Oct 2005 00:30:39 -0000 Received: from bes.cs.utk.edu (160.36.56.220) by a.mx.sunsite.dk with SMTP; 24 Oct 2005 00:30:37 -0000 Received: from localhost (bes [127.0.0.1]) by bes.cs.utk.edu (Postfix) with ESMTP id 1D15D27388; Sun, 23 Oct 2005 20:30:35 -0400 (EDT) Received: from bes.cs.utk.edu ([127.0.0.1]) by localhost (bes [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 05352-07; Sun, 23 Oct 2005 20:30:33 -0400 (EDT) Received: from namib.cs.utk.edu (namib.cs.utk.edu [160.36.59.92]) by bes.cs.utk.edu (Postfix) with ESMTP id 6C36C27387; Sun, 23 Oct 2005 20:30:33 -0400 (EDT) Received: by namib.cs.utk.edu (Postfix, from userid 10605) id 3262836EE5; Sun, 23 Oct 2005 20:30:33 -0400 (EDT) Date: Sun, 23 Oct 2005 20:30:33 -0400 From: Chris Johnson To: DervishD , Zsh Users Subject: Re: Printing square brackets and backslashes Message-ID: <20051024003033.GA2835@namib.cs.utk.edu> References: <20051023214319.GA633@DervishD> <20051024000408.GA1124@DervishD> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20051024000408.GA1124@DervishD> User-Agent: Mutt/1.5.9i X-Virus-Scanned: by amavisd-new with ClamAV and SpamAssasin at cs.utk.edu X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00 autolearn=ham version=3.0.4 DervishD sent me the following 0.9K: > > Hi all :) > > > > $ print \[\\\] > > [] > > $ /bin/echo -e \[\\\] > > [\] > > $ print -r \[\\\] > > [\] > > $ print \\ > > \ > > I can understand the first case, but I don't understand the last > one: in the first case, what I misunderstood is that the shell quotes > the chars, producing "[\]" and "print" prints them, interpreting some > escape directives: "[]". But in the last case, nothing should then be > printed, because zsh quotes the backslash and "print" gets a single > backslash, that is, an empty escape directive that shouldn't print > anything :? Is "print" assuming that a single backslash is not an > empty escape directive? Is a single, isolated backslash a synonim for > "\\"? This is in the zsh user's guide at: http://zsh.sourceforge.net/Guide/zshguide03.html#l32 Look under section 3.2.1, Builtins for printing. # -------------------------------------------------------------------- Secondly, those backslashes can land you in real quoting difficulties. Normally a backslash on the command line escapes the next character --- this is a different form of escaping to print's --- so print \n doesn't produce a newline, it just prints out an `n'. So you need to quote that. This means print \\ passes a single backslash to quote, and print \\n or print '\n' prints a newline (followed by the extra one that's usually there). To print a real backslash, you would thus need print \\\\ Actually, you can get away with the two if there's nothing else after --- print just shrugs its shoulders and outputs what it's been given --- but that's not a good habit to get into. -- Chris Johnson cjohnson@cs.utk.edu http://www.cs.utk.edu/~cjohnson