* variable expansion which will remove a file extension
@ 2006-03-17 23:52 zzapper
2006-03-18 0:03 ` Dominic Mitchell
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: zzapper @ 2006-03-17 23:52 UTC (permalink / raw)
To: zsh-users
Hi,
How do I write a variable expansion which will remove a file extension eg
fred.tex -> fred
This is what I hacked:-
zip=${file//\.[[:alnum:]]*/}
--
http://successtheory.com/ 100 FREE Success and Self-Improvement Tips
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: variable expansion which will remove a file extension
2006-03-17 23:52 variable expansion which will remove a file extension zzapper
@ 2006-03-18 0:03 ` Dominic Mitchell
2006-03-18 0:08 ` paul Lew
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Dominic Mitchell @ 2006-03-18 0:03 UTC (permalink / raw)
To: zzapper; +Cc: zsh-users
zzapper wrote:
> Hi,
> How do I write a variable expansion which will remove a file extension eg
> fred.tex -> fred
>
> This is what I hacked:-
>
> zip=${file//\.[[:alnum:]]*/}
How about:
zip=${file%.*}
-Dom
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: variable expansion which will remove a file extension
2006-03-17 23:52 variable expansion which will remove a file extension zzapper
2006-03-18 0:03 ` Dominic Mitchell
@ 2006-03-18 0:08 ` paul Lew
2006-03-18 0:23 ` Bart Schaefer
2006-03-18 0:42 ` Christian Schneider
3 siblings, 0 replies; 6+ messages in thread
From: paul Lew @ 2006-03-18 0:08 UTC (permalink / raw)
To: zzapper; +Cc: zsh-users
>>>>> "zzapper" == zzapper <david@tvis.co.uk> writes:
zzapper> Hi, How do I write a variable expansion which will remove
zzapper> a file extension eg fred.tex -> fred
zzapper> This is what I hacked:-
zzapper> zip=${file//\.[[:alnum:]]*/}
$file:r
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: variable expansion which will remove a file extension
2006-03-17 23:52 variable expansion which will remove a file extension zzapper
2006-03-18 0:03 ` Dominic Mitchell
2006-03-18 0:08 ` paul Lew
@ 2006-03-18 0:23 ` Bart Schaefer
2006-03-18 0:43 ` zzapper
2006-03-18 0:42 ` Christian Schneider
3 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2006-03-18 0:23 UTC (permalink / raw)
To: zsh-users
On Mar 17, 11:52pm, zzapper wrote:
}
} How do I write a variable expansion which will remove a file extension eg
} fred.tex -> fred
${var:r}
13.1.4 Modifiers
----------------
After the optional word designator, you can add a sequence of one or
more of the following modifiers, each preceded by a `:'. These
modifiers also work on the result of _filename generation_ and
_parameter expansion_, except where noted.
h
Remove a trailing pathname component, leaving the head. This works
like `dirname'.
r
Remove a filename extension of the form `.XXX', leaving the root
name.
e
Remove all but the extension.
t
Remove all leading pathname components, leaving the tail. This
works like `basename'.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: variable expansion which will remove a file extension
2006-03-18 0:23 ` Bart Schaefer
@ 2006-03-18 0:43 ` zzapper
0 siblings, 0 replies; 6+ messages in thread
From: zzapper @ 2006-03-18 0:43 UTC (permalink / raw)
To: zsh-users
Bart Schaefer <schaefer@brasslantern.com> wrote in
news:060317162338.ZM18794@torch.brasslantern.com:
> ----------------
> h
> Remove a trailing pathname component, leaving the head. This
> works like `dirname'.
>
> r
> Remove a filename extension of the form `.XXX', leaving the root
> name.
>
> e
> Remove all but the extension.
>
> t
> Remove all leading pathname components, leaving the tail. This
> works like `basename'.
#!zsh
# test script
fred='/bin/path/fred.txt'
echo ${fred:e}
echo ${fred:t}
echo ${fred:r}
echo ${fred:h}
echo ${fred:h:h}
echo ${fred:t:r}
--
http://successtheory.com/ 100 FREE Success and Self-Improvement Tips
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: variable expansion which will remove a file extension
2006-03-17 23:52 variable expansion which will remove a file extension zzapper
` (2 preceding siblings ...)
2006-03-18 0:23 ` Bart Schaefer
@ 2006-03-18 0:42 ` Christian Schneider
3 siblings, 0 replies; 6+ messages in thread
From: Christian Schneider @ 2006-03-18 0:42 UTC (permalink / raw)
To: zsh-users
* zzapper <david@tvis.co.uk> typed:
> How do I write a variable expansion which will remove a file extension eg
> fred.tex -> fred
>
> This is what I hacked:-
>
> zip=${file//\.[[:alnum:]]*/}
Use ``${foo:r}''. ":r" remove a filename extension; its described in
zshexpn(1) /Modifiers
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2006-03-18 0:44 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-17 23:52 variable expansion which will remove a file extension zzapper
2006-03-18 0:03 ` Dominic Mitchell
2006-03-18 0:08 ` paul Lew
2006-03-18 0:23 ` Bart Schaefer
2006-03-18 0:43 ` zzapper
2006-03-18 0:42 ` Christian Schneider
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).