From owner-freebsd-questions@FreeBSD.ORG Thu Jul 31 19:27:06 2003 Return-Path: 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 66AA837B401 for ; Thu, 31 Jul 2003 19:27:06 -0700 (PDT) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by mx1.FreeBSD.org (Postfix) with ESMTP id C0A3843F93 for ; Thu, 31 Jul 2003 19:27:05 -0700 (PDT) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.12.9/8.12.9) id h712R55V033677; Thu, 31 Jul 2003 21:27:05 -0500 (CDT) (envelope-from dan) Date: Thu, 31 Jul 2003 21:27:05 -0500 From: Dan Nelson To: Chuck Swiger Message-ID: <20030801022705.GC13080@dan.emsphone.com> References: <3F29C589.4030009@users.sourceforge.net> <3F29CD39.9080505@mac.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3F29CD39.9080505@mac.com> X-OS: FreeBSD 5.1-CURRENT X-message-flag: Outlook Error User-Agent: Mutt/1.5.4i cc: freebsd-questions@freebsd.org cc: Rob Lahaye Subject: Re: tcsh script: quote and spaces problems X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Aug 2003 02:27:06 -0000 In the last episode (Jul 31), Chuck Swiger said: > Rob Lahaye wrote: > [ ... ] > >Any solutions for this problem with quotes and spaces in tcsh > >script? Or is tcsh not suitable for this kind of things? > > Ugh, the latter. :-) /bin/sh handles nested quoting right, but crunches > the space together: > > % foo="-f \"t \"" > % echo $foo > -f "t " > > % foo='-f "t "' > % echo $foo > -f "t " Actually it doesn't. You get this result because sh splits variables on $IFS before passing the result to a command, so what echo gets is argv[1]="-f \"t" argv[2]="\"" , and echo always prints its arguments separated by a space. You can verify that the variable is set correctly by running "set | grep -a foo". To pass the entire string as one argument, run echo "$foo". > ...however, you might be able to muck with $IFS and get better results. > Also, ZSH seems to do exactly what you expected: > > 64-sec% foo="-f \"t \"" > 65-sec% echo $foo > -f "t " This is because zsh passes variables directly to commands, unless the SH_WORD_SPLIT flag is set. You can force spltting with the ${=foo} syntax. -- Dan Nelson dnelson@allantgroup.com