help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Change filename extension in Bash array


From: Andreas Kusalananda Kähäri
Subject: Re: Change filename extension in Bash array
Date: Mon, 25 Jan 2021 11:17:29 +0100

On Mon, Jan 25, 2021 at 10:47:03AM +0100, Reuti wrote:
> 
> 
> > Am 25.01.2021 um 10:41 schrieb Jeffrey Walton <noloader@gmail.com>:
> > 
> > Hi Everyone,
> > 
> > Search is not turning up the results I am looking for. I would appreciate 
> > help.
> > 
> > I have an array with filenames:
> > 
> >    odt_files=("ch1.odt" "ch2.odt" "ch3.odt" ...)
> > 
> > I convert the ODT to a PDF using lowriter, which is a LibreOffice utility.
> > 
> > I need to combine the PDFs using pdfunite for the final document.
> > 
> > How do I create an array of filenames using the PDF extension given
> > the ODT extension in odt_files?
> > 
> >    # What is needed here?
> >    pdf_files=${odt_files}
> > 
> > Here are some things I know do not work:
> > 
> >    pdf_files=("${odt_files[@]/.odt/.pdf}")
> >    pdf_files=("${odt_files/.odt/.pdf}")
> >    pdf_files="${odt_files[@]/.odt/.pdf}"
> >    pdf_files="${odt_files/.odt/.pdf}"
> 
> pdf_files=(${odt_files[@]/.odt/.pdf})

You probably want "${odt_files[@]/%.odt/.pdf}" here, including the
quotes and the %.

The quotes are needed in case any string contains characters from
$IFS (space, tabs, newlines by default), or if they contain globbing
patterns.

The % is needed to only delete the .odt substring from the end of each
element (not the first found .odt).



-- 
Andreas (Kusalananda) Kähäri
SciLifeLab, NBIS, ICM
Uppsala University, Sweden

.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]