On Sun, Jul 08, 2018 at 10:26:41PM +0900, Anton Lindqvist wrote:
> On Sun, Jul 08, 2018 at 05:18:28PM +0900, Anton Lindqvist wrote:
> > On Sat, Jul 07, 2018 at 10:06:41AM +0200, Andreas Kusalananda Kähäri wrote:
> > > Hi,
> > >
> > > I'm not sure this is a bug or a misunderstanding by me, but it sure
> > > surprised me:
> > >
> > >     $ set -- file.txt txt
> > >
> > >     $ printf 'Two values: %s %s\n' "$1" "$2"
> > >     Two values: file.txt txt
> > >
> > >     $ printf 'First value with suffix removed: %s\n' "${1%.*}"
> > >     First value with suffix removed: file
> > >
> > >     $ printf 'First value with second value removed from end: %s\n' 
> > > "${1%.$2}"
> > >     First value with second value removed from end: txt
> > >
> > > I would have expected the last two parameter expansion to generate the
> > > same result ("file").  Also, removing the dot ("${1%$2}") generates an
> > > empty result.
> > >
> > > Note that using variables, this works as expected:
> > >
> > >     $ filename=file.txt
> > >     $ suffix=txt
> > >     $ printf 'First value with second value removed from end: %s\n' 
> > > "${filename%.$suffix}"
> > >     First value with second value removed from end: file
> > >
> > > This is on a current system using either /bin/sh or /bin/ksh and the
> > > effect of trying to remove from the start of the string is similar.
> >
> > That's indeed a bug. Lookup of positional arguments ($1 and $2) is done
> > using global() which in turn returns a pointer to static storage for
> > read-only variables (positional arguments are read-only). So the second
> > call to global() overwrites the previous one. Here's a first stab in
> > which read-only variables are copied during expansion. I ended up adding
> > a new function in order to avoid deep indenting. Also, zero st_head in
> > order to simplify the free loop; otherwise st_head.var would contain
> > stack garbage.
> >
> > Comments? OK?
>
> A fix has now been committed, thanks for the report!

Thanks! And thanks for picking it up and fixing it so promptly!

Andreas

--
Andreas Kusalananda Kähäri,
National Bioinformatics Infrastructure Sweden (NBIS),
Uppsala University, Sweden.








När du har kontakt med oss på Uppsala universitet med e-post så innebär det att 
vi behandlar dina personuppgifter. För att läsa mer om hur vi gör det kan du 
läsa här: http://www.uu.se/om-uu/dataskydd-personuppgifter/

E-mailing Uppsala University means that we will process your personal data. For 
more information on how this is performed, please read here: 
http://www.uu.se/om-uu/dataskydd-personuppgifter/

Reply via email to