From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25980 invoked by alias); 27 Mar 2017 01:44:11 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 22622 Received: (qmail 5322 invoked from network); 27 Mar 2017 01:44:11 -0000 X-Qmail-Scanner-Diagnostics: from kahlil.inlv.org by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(37.59.109.123):SA:0(-0.0/5.0):. Processed in 1.832086 secs); 27 Mar 2017 01:44:11 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RP_MATCHES_RCVD autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: martijn@inlv.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at inlv.org does not designate permitted sender hosts) Subject: Re: spaces in filenames should be a crime. To: zsh-users@zsh.org References: <0c1b9d89-edd0-a027-e2f1-d01c2d68fa4e@eastlink.ca> <20170326211805.GA8170@fujitsu.shahaf.local2> From: Martijn Dekker Message-ID: <7d210765-c730-da1d-bb22-19f26ce02c6e@inlv.org> Date: Mon, 27 Mar 2017 03:44:27 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Op 27-03-17 om 00:41 schreef Ray Andrews: > On 26/03/17 02:18 PM, Daniel Shahaf wrote: >> You could replace the whole function with: >> mostrecent() { ls -l -- **/*(.om[1]) } > > Yeah, my original was just something I found on the net and didn't > bother to improve upon until it crashed and burned on a space in the > directory name. I'm not surprised that our 'ls' can do it all by itself. Note that 'ls' is an external command that doesn't do anything but list files given to it as arguments. It cannot expand any glob patterns (with *, etc.); that's the shell's job. The shell resolves the glob pattern and hands 'ls' the expanded list of arguments. This applies to every other command as well, and even to shell functions. (This is a fundamental difference with DOS/Windows batch files, where every command is expected to resolve patterns by itself.) Shell globbing can also be dangerous if any file names start with '-'; the command may interpret these as options. Most commands support a standard method of neutralising that: the special option '--' to disable option parsing for any subsequent command. A common alternative idiom is to prepend './' to the glob pattern so that every argument expanded from it also starts with './' (and hence never '-'). > DTRT? FYI: http://www.acronymfinder.com/ HTH. HAND. ;-) - M.