* regular expressions and setting variables?
@ 2014-06-10 5:04 William G. Scott
2014-06-10 6:17 ` Roman Neuhauser
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: William G. Scott @ 2014-06-10 5:04 UTC (permalink / raw)
To: zsh-users
Hi folks:
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.
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. What do I need to do to get this working?
Thanks in advance.
Bill Scott
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: regular expressions and setting variables?
2014-06-10 5:04 regular expressions and setting variables? William G. Scott
@ 2014-06-10 6:17 ` Roman Neuhauser
2014-06-10 8:45 ` Phil Pennock
2014-06-10 14:11 ` zzapper
2 siblings, 0 replies; 6+ messages in thread
From: Roman Neuhauser @ 2014-06-10 6:17 UTC (permalink / raw)
To: William G. Scott; +Cc: zsh-users
# wgscott@ucsc.edu / 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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: regular expressions and setting variables?
2014-06-10 5:04 regular expressions and setting variables? William G. Scott
2014-06-10 6:17 ` Roman Neuhauser
@ 2014-06-10 8:45 ` Phil Pennock
2014-06-10 14:26 ` William G. Scott
2014-06-10 14:11 ` zzapper
2 siblings, 1 reply; 6+ messages in thread
From: Phil Pennock @ 2014-06-10 8:45 UTC (permalink / raw)
To: William G. Scott; +Cc: zsh-users
On 2014-06-09 at 22:04 -0700, William G. Scott wrote:
> 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. What do I need to do to get this working?
${name/pattern/repl} does not use regular expressions, it uses shell
patterns.
Described in zshexpn(1) under "PARAMETER EXPANSION".
% echo ${JUNK/%./_}
R.E.M_
-Phil
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: regular expressions and setting variables?
2014-06-10 5:04 regular expressions and setting variables? William G. Scott
2014-06-10 6:17 ` Roman Neuhauser
2014-06-10 8:45 ` Phil Pennock
@ 2014-06-10 14:11 ` zzapper
2 siblings, 0 replies; 6+ messages in thread
From: zzapper @ 2014-06-10 14:11 UTC (permalink / raw)
To: zsh-users
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 782 bytes --]
"William G. Scott" <wgscott@ucsc.edu> wrote in
news:157E3510-D220-4C1C-A452-93DE96DA4363@chemistry.ucsc.edu:
> Hi folks:
>
> Im 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
:
>
> 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/\.$/_}
>
JUNK=R.E.M.
print ${JUNK/\.(#e)/\_}
--
zzapper
https://twitter.com/dailyzshtip
---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: regular expressions and setting variables?
2014-06-10 8:45 ` Phil Pennock
@ 2014-06-10 14:26 ` William G. Scott
0 siblings, 0 replies; 6+ messages in thread
From: William G. Scott @ 2014-06-10 14:26 UTC (permalink / raw)
To: Phil Pennock; +Cc: zsh-users
On Jun 10, 2014, at 1:45 AM, Phil Pennock <zsh-workers+phil.pennock@spodhuis.org> wrote:
>
> ${name/pattern/repl} does not use regular expressions, it uses shell
> patterns.
>
> Described in zshexpn(1) under "PARAMETER EXPANSION".
>
> % echo ${JUNK/%./_}
> R.E.M_
>
> -Phil
Thanks very much to all who replied. I didn’t even realize there was a difference (sorry).
— Bill
^ permalink raw reply [flat|nested] 6+ messages in thread
* regular expressions and setting variables?
@ 2014-06-10 5:02 William G. Scott
0 siblings, 0 replies; 6+ messages in thread
From: William G. Scott @ 2014-06-10 5:02 UTC (permalink / raw)
To: zsh-users
Hi folks:
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.
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. What do I need to do to get this working?
Thanks in advance.
Bill Scott
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-06-10 14:26 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-10 5:04 regular expressions and setting variables? William G. Scott
2014-06-10 6:17 ` Roman Neuhauser
2014-06-10 8:45 ` Phil Pennock
2014-06-10 14:26 ` William G. Scott
2014-06-10 14:11 ` zzapper
-- strict thread matches above, loose matches on Subject: below --
2014-06-10 5:02 William G. Scott
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).