Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: /non/existant/path(:h)



On Tue, 27 May 2008 10:29:46 +0200
Sebastian Stark <seb-zsh@xxxxxxxxxxx> wrote:
> I say this is not exactly true since if you expand:
> 
>   $myvar(:h)
> 
> when myvar contains a path that does not exist it will expand to the  
> empty string if nullglob is set or, if nullglob is unset, it will lead  
> to an error. This is not very close to a replacement of dirname(1),  
> like suggested by the manpage.

You want ${myvar:h}.  When you use globbing syntax, it turns the whole
expression into a pattern match, so you get the unwanted side effect.
When you use variable syntax that doesn't happen.

Index: Doc/Zsh/expn.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/expn.yo,v
retrieving revision 1.89
diff -u -r1.89 expn.yo
--- Doc/Zsh/expn.yo	3 Apr 2008 21:10:58 -0000	1.89
+++ Doc/Zsh/expn.yo	27 May 2008 08:40:42 -0000
@@ -2176,12 +2176,13 @@
 
 If a `tt(:)' appears in a qualifier list, the remainder of the expression in
 parenthesis is interpreted as a modifier (see noderef(Modifiers)
-in noderef(History Expansion)).  Note that
-each modifier must be introduced by a separate `tt(:)'.  Note also that the
-result after modification does not have to be an existing file.  The
-name of any existing file can be followed by a modifier of the form
-`tt((:..))' even if no actual filename generation is performed.
-Thus:
+in noderef(History Expansion)).  Each modifier must be introduced by a
+separate `tt(:)'.  Note also that the result after modification does not
+have to be an existing file.  The name of any existing file can be followed
+by a modifier of the form `tt((:..))' even if no actual filename generation
+is performed, although note that the presence of the parentheses
+causes the entire expression to be subjected to any global pattern matching
+options such as tt(NULL_GLOB). Thus:
 
 example(ls *(-/))
 


-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



Messages sorted by: Reverse Date, Date, Thread, Author