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

Re: regular expressions and setting variables?



# wgscott@xxxxxxxx / 2014-06-09 22:04:20 -0700:
> I?m trying to emulate how iTunes changes some names of directories it
> creates based on names of artists.  For example, albums by the group
> R.E.M. are stored in a directory it creates called R.E.M_  
> 
> The final full-stop is replaced with an underscore, I assume to avoid
> complications in the unix filesystem.

i doubt that.  "the unix filesystem" does not care about names at all,
well, almost: a filename cannot contain slashes and null bytes.
slash, because these are used to separate "foo" from "bar" in "foo/bar",
and null bytes, because "foo" and "bar" are stored in the filesystem
as C strings, where the null byte is used as terminator.

windows filesystems OTOH, among other limitations, prohibit names
ending with a dot.

> This works:
> 
> JUNK=R.E.M.
> print ${JUNK}| perl -p -e 's|\.$|_|g?
> 
> It returns
> R.E.M_
> 
> 
> But if I try to do this:  
> 
> print ${JUNK/\.$/_}   
> 
> it returns               
> R.E.M.
> 
> I assume I am not using the correct regexp.

kinda, the ${param/pat/rep} operation does not use regexps, the pattern
expects the globbing ("filename generation") syntax.

> What do I need to do to get this working?

man zshexpn.

-- 
roman



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