From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18670 invoked by alias); 22 Apr 2016 05:26:39 -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: 21475 Received: (qmail 29288 invoked from network); 22 Apr 2016 05:26:35 -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=-1.9 required=5.0 tests=BAYES_00,HTML_MESSAGE, T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=benizi-com.20150623.gappssmtp.com; s=20150623; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=Mtvc8myr5YqofrfohPkBEUzIjhfl17W/HOnAzPHzEiM=; b=hMWIqkw6jwzkWMZo1HDmp13K320qrfISpGQFIbxelkYB5lIe/xbtBQYJlSW9Pz2Dvn Ib6gcp4bmNaR1OmV8JJXxVlYh+x+wCAbHF+wJreNl8QIaVtJ5FtjZavZx3ikQGHAPShw bHNZx34F5ZC9xbngL6sbK7dnZnIJlHSTs1EGUyyvtZ1DztLvDz5Ly3vmmdnv37LBhJCV n0ZdXkPH8u/m0MCEFjTuM4WLiWbH43Lq0ToiebgO/SAPgwS96HY42b1sO+JlQWq8kYvp b8ge0w+iEiqcU/R3KK/IDGXJm0gls2m8OVxwXfCt+FDjwgG262zP5WbPcNC7nR9fLXla 45bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=Mtvc8myr5YqofrfohPkBEUzIjhfl17W/HOnAzPHzEiM=; b=mE6YeEL93eaUiwxTXH8S8wR+8mNHt/dDogmMp+IaSqW1Z4MtdrBapKMCEgmGmyuiz4 J7oeRcJZgeBRKDiWdQf1cSXUABMVVefpa5bZ57rTNutgLoDnEWN6kTxwwBwmKrTV09/7 T+C1s27oorVA66+LWF+vn8eOQPrs+HPFtLWZ3s+pJxJPH2reP6KW27AVN/a84WPTrPjH ds0O9Usv/yalHa+jTdWCOg8Row37cZEAvIqOq4phXQCOJzpJZWHNllT8VzvoHvJbmu4n qYNTuoitVnCJpPC+XLJ0zN8jH0i/kUtUVpE38GpnrTkl4+bi1/dYZjC0ff+kngPlB2Pt tYSw== X-Gm-Message-State: AOPr4FV8ZvTKchMDFPpqjvXSfl6XpMHtdyJ8OCF4+rPo53xTWP4SgHFS8ZUSZpHscOtgLUks33KGzOB6/4yrxw== X-Received: by 10.157.35.48 with SMTP id j45mr2198453otb.138.1461302791091; Thu, 21 Apr 2016 22:26:31 -0700 (PDT) MIME-Version: 1.0 Sender: benizi@benizi.com In-Reply-To: <160420133446.ZM13832@torch.brasslantern.com> References: <8760vdrt5y.fsf@student.uu.se> <160420133446.ZM13832@torch.brasslantern.com> From: "Benjamin R. Haskell" Date: Fri, 22 Apr 2016 01:26:11 -0400 X-Google-Sender-Auth: pgO27dcJ7Q0KqMD37j7WLsYh8ic Message-ID: Subject: Re: virtual files? To: Bart Schaefer Cc: Zsh-Users List Content-Type: multipart/alternative; boundary=001a113db366c5ce2005310c11b9 --001a113db366c5ce2005310c11b9 Content-Type: text/plain; charset=UTF-8 On Wed, Apr 20, 2016 at 4:34 PM, Bart Schaefer wrote: > On Apr 19, 11:32pm, Benjamin R. Haskell wrote: > } > } Using the `=()` substitution ZyX mentions: > } > } () { > } local tmp=$1 > } wget -q $link -O $tmp > } echo -n \$ > } grep \"answer\" $tmp | cut -d \$ -f 2 | cut -d \< -f 1 > } } =(:) > } > } The '() { ... }' construct is an anonymous function, just for controlling > } the scope of the temporary file, and for passing it in as a positional > } parameter. It has the disadvantage that it won't remove the tmp file if > } something goes wrong. > > In fact the point of using =(:) is that it WILL remove the tmp file if > something goes wrong (unless it's something completely catastrophic like > the shell itself crashing, but in that case an explicit "rm" wouldn't > work either). > Right, it's the "unless" I'm worried about: ## temp file isn't deleted on exit, so it's still there to be removed $ ( () { local tmp=$1 ; echo $tmp ; exit 1 } =(:) ) | xargs rm --verbose removed '/tmp/zsh9OzJL1' ## temp file is deleted with exit trap $ ( () { local tmp=$1 ; trap "rm $tmp" INT QUIT EXIT ; echo $tmp ; exit 1 } =(:) ) | xargs rm --verbose rm: cannot remove '/tmp/zshhzsFQo': No such file or directory Instead of exit traps, you can use "always" blocks: > > () { > local tmp=$1; > { > : do stuff with $tmp > exit > } always { > rm $tmp > } > } =(:) > Cool! ~Half my scripts have no need of POSIX-ness, so that'll come in handy. -- Best, Ben --001a113db366c5ce2005310c11b9--