It's kinda basic but surprised me a lot.
Im using on WSL (Unubtu 18.04 LTS) poppler-utils
for managing PDFs, usually it's as simple as
cd <DIR of bunch of PDFs>
pdfunite `ls` out.pdf
as pdfunite
SYNOPSIS just requires list of PDFs to merge and output file name.
But recently I got some files with characters specific for my county as ó, ś, ź and then I'm getting following I/O error:
I/O Error: Couldn't open file 'Og<c3><b3>rki': No such file or directory.
Syntax Error: Could not merge damaged documents ('Og<c3><b3>rki')
(Ogórki witch is polish for cucumbers ;) )
C3 B3 of course corresponds to UNICODE:
U+00F3 ó c3 b3 LATIN SMALL LETTER O WITH ACUTE
But is there an option to force ls
to pass such chars in correct format as well when they are substitued?
Or problem is elsewhere, as when I'm substituting them with echo
:
echo `ls`
I'm getting correctly formatted UNICODE chars.
Thanks in advance!
*
? I.e.pdfunite * out.pdf
– Kusalananda Jun 14 '21 at 10:51*
is "safer"? – Tomas Jun 14 '21 at 11:02ls
can print any file name, including the ones with spaces in them, line breaks, semicolons..., and your shell will then take that string and tear it apart into individual arguments, incorrectly.*
tells your shell to take exactly one file name per argument, never a problem. "Don't usels
to get a list of files in shell scripts" is a rule that usually we hammer into beginners very early, so this might be your lucky day :) – Marcus Müller Jun 14 '21 at 11:15ls
is always unsafe precisely because it leads to this sort of error. See https://mywiki.wooledge.org/ParsingLs and Why *not* parse `ls` (and what to do instead)?. – terdon Jun 14 '21 at 11:16ls
output. Apart from @terdon's examples mentioned before, here you can see how it manifests in real life. – tansy Jun 14 '21 at 11:38*
either, it should be*.pdf
; output of ls is designed to be read, not substituted. – user10489 Jun 14 '21 at 11:55$ cat \
ls b*` > cc` but it worked, so I'm not sure. The others have spaces in name which disqualifies ls usage. – tansy Jun 14 '21 at 12:13