From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6606 invoked from network); 26 Jan 2005 17:07:41 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 26 Jan 2005 17:07:41 -0000 Received: (qmail 69182 invoked from network); 26 Jan 2005 17:07:35 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 26 Jan 2005 17:07:35 -0000 Received: (qmail 14789 invoked by alias); 26 Jan 2005 17:07:26 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8430 Received: (qmail 14769 invoked from network); 26 Jan 2005 17:07:25 -0000 Received: from unknown (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 26 Jan 2005 17:07:25 -0000 Received: (qmail 68088 invoked from network); 26 Jan 2005 17:06:43 -0000 Received: from smtp-out4.blueyonder.co.uk (195.188.213.7) by a.mx.sunsite.dk with SMTP; 26 Jan 2005 17:06:38 -0000 Received: from localhost ([82.41.211.153]) by smtp-out4.blueyonder.co.uk with Microsoft SMTPSVC(5.0.2195.6713); Wed, 26 Jan 2005 17:07:11 +0000 Resent-From: Stephane Chazelas Resent-Date: Wed, 26 Jan 2005 17:08:13 +0000 Resent-Message-ID: <20050126170813.GC9469@sc> Resent-To: Zsh Users List Date: Tue, 25 Jan 2005 15:03:38 +0000 From: Stephane Chazelas To: zsh-users@sunsite.dk Subject: Re: Expansion order Message-ID: <20050125150338.GA12513@sc> Mail-Followup-To: zsh-users@sunsite.dk References: <20050125144150.GP29543@suse.de> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20050125144150.GP29543@suse.de> User-Agent: Mutt/1.5.6i X-OriginalArrivalTime: 26 Jan 2005 17:07:11.0628 (UTC) FILETIME=[79C65CC0:01C503C9] X-Spam-Checker-Version: SpamAssassin 3.0.2 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, score=-2.4 required=6.0 tests=AWL,BAYES_00 autolearn=ham version=3.0.2 X-Spam-Hits: -2.4 On Tue, Jan 25, 2005 at 03:41:50PM +0100, Mads Martin Joergensen wrote: > Hey together, > > $ export LS_OPTIONS="-N --color=tty -T 0" > $ alias ls='ls $LS_OPTIONS' > $ ls > /bin/ls: invalid option -- > Try `/bin/ls --help' for more information. > > How come the zsh is doing the expansion in this case differently from > csh, tcsh, bash and sh? > > If it's a configuration option or such, I would be grateful to know. I > looked through the expansion man-pages, but I might have missed it. [...] See question 3.1 in the FAQ http://zsh.sunsite.dk/FAQ/zshfaq03.html#l17 Even with other Bourne like shells, it's not a good idea to write it this way as it relies on the current value of IFS. (if you change IFS, your ls will stop working). Here, you want LS_OPTIONS to be an array, not a string. LS_OPTIONS=(-N --color=tty -T 0) alias ls='ls "${LS_OPTIONS[@]"' Or if LS_OPTIONS has to be an environment variable, then you'd better ensure the the right value of IFS is used: export LS_OPTIONS='-N,--color=tty,-T,0' ls() { ( IFS=, set -f exec command ls $LS_OPTIONS "$@" ) } or for zsh, where word splitting and filename generation are thanksfully not implicit: export LS_OPTIONS='-N,--color=tty,-T,0' ls() { local IFS=, command ls $=LS_OPTIONS "$@" } " " (space) is not a good choice of for a separated list, as it doesn't allows empty elements, that's why I used "," instead above. Alternatively, you may consider "LS_OPTIONS" as a part of a shell command line, so that can have: LS_OPTIONS='-foo "arg with spaces" -empty ""' or LS_OPTIONS='--color="$([ -t 1 ] && echo yes || echo no)"' Then, you can use it as: ls() { eval "command ls $LS_OPTIONS \"\$@\"" } Which should work in zsh as well as in POSIX shells. -- Stéphane