В продолжение pdflatex: название файла с выводом
Имею такой однострочник /usr/bin/pdfmargins
INPUT_PDF_FILE="$1" OUTPUT_PDF_FILE="${INPUT_PDF_FILE%.pdf}.margins" pdflatex -jobname "$OUTPUT_PDF_FILE" '\documentclass{article}\usepackage{pdfpages}\begin{document}\includepdf[pages=-,trim=1cm 0cm 1cm 0cm]{"$INPUT_PDF_FILE"}\end{document}'
pdflatex остаётся недоволен подстановкой, которую ему даёт bash:
$ pdfmargins KV_2034__2021__ZR.pdf
This is pdfTeX, Version 3.141592653-2.6-1.40.24 (TeX Live 2022/Debian) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
LaTeX2e <2022-11-01> patch level 1
L3 programming layer <2023-01-16>
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2022/07/02 v1.4n Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo))
(/usr/share/texlive/texmf-dist/tex/latex/pdfpages/pdfpages.sty
(/usr/share/texlive/texmf-dist/tex/latex/base/ifthen.sty)
(/usr/share/texlive/texmf-dist/tex/latex/tools/calc.sty)
(/usr/share/texlive/texmf-dist/tex/latex/eso-pic/eso-pic.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/share/texlive/texmf-dist/tex/latex/xcolor/xcolor.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics-cfg/color.cfg)
(/usr/share/texlive/texmf-dist/tex/latex/graphics-def/pdftex.def)
(/usr/share/texlive/texmf-dist/tex/latex/graphics/mathcolor.ltx)))
(/usr/share/texlive/texmf-dist/tex/latex/graphics/graphicx.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/share/texlive/texmf-dist/tex/latex/graphics-cfg/graphics.cfg)))
(/usr/share/texlive/texmf-dist/tex/latex/pdfpages/pppdftex.def))
(/usr/share/texlive/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def)
No file .aux.
pdflatex: Not writing to .aux (openout_any = p).
! I can't write on file `.aux'.
\document ...ate \openout \@mainaux \jobname .aux
\immediate \write \@mainau...
<*> ...ticle}\usepackage{pdfpages}\begin{document}
\includepdf[pages=-,trim=1...
(Press Enter to retry, or Control-D to exit; default file extension is `.tex')
Please type another output file name:
Если посмотреть на дебагер, все значения переменных как будто бы как нужно:
$ bash -x pdfmargins KV_2034__2021__ZR.pdf
+ '[' -z '' ']'
+ return
+ INPUT_PDF_FILE=KV_2034__2021__ZR.pdf
+ OUTPUT_PDF_FILE=KV_2034__2021__ZR.margins
+ pdflatex -jobname '' '\documentclass{article}\usepackage{pdfpages}\begin{document}\includepdf[pages=-,trim=1cm 0cm 1cm 0cm]{}\end{document}'
This is pdfTeX, Version 3.141592653-2.6-1.40.24 (TeX Live 2022/Debian) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
LaTeX2e <2022-11-01> patch level 1
L3 programming layer <2023-01-16>
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2022/07/02 v1.4n Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo))
(/usr/share/texlive/texmf-dist/tex/latex/pdfpages/pdfpages.sty
(/usr/share/texlive/texmf-dist/tex/latex/base/ifthen.sty)
(/usr/share/texlive/texmf-dist/tex/latex/tools/calc.sty)
(/usr/share/texlive/texmf-dist/tex/latex/eso-pic/eso-pic.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/share/texlive/texmf-dist/tex/latex/xcolor/xcolor.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics-cfg/color.cfg)
(/usr/share/texlive/texmf-dist/tex/latex/graphics-def/pdftex.def)
(/usr/share/texlive/texmf-dist/tex/latex/graphics/mathcolor.ltx)))
(/usr/share/texlive/texmf-dist/tex/latex/graphics/graphicx.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/share/texlive/texmf-dist/tex/latex/graphics-cfg/graphics.cfg)))
(/usr/share/texlive/texmf-dist/tex/latex/pdfpages/pppdftex.def))
(/usr/share/texlive/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def)
No file .aux.
pdflatex: Not writing to .aux (openout_any = p).
! I can't write on file `.aux'.
\document ...ate \openout \@mainaux \jobname .aux
\immediate \write \@mainau...
<*> ...ticle}\usepackage{pdfpages}\begin{document}
\includepdf[pages=-,trim=1...
(Press Enter to retry, or Control-D to exit; default file extension is `.tex')
Please type another output file name:
Опять таки, если подставить значения переменных в саму строку скрипта, то работает:
$ pdflatex -jobname "KV_2034__2021__ZR.margins" '\documentclass{article}\usepackage{pdfpages}\begin{document}\includepdf[pages=-,trim=1cm 0cm 1cm 0cm]{"KV_2034__2021__ZR.pdf"}\end{document}'
This is pdfTeX, Version 3.141592653-2.6-1.40.24 (TeX Live 2022/Debian) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
LaTeX2e <2022-11-01> patch level 1
L3 programming layer <2023-01-16>
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2022/07/02 v1.4n Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo))
(/usr/share/texlive/texmf-dist/tex/latex/pdfpages/pdfpages.sty
(/usr/share/texlive/texmf-dist/tex/latex/base/ifthen.sty)
(/usr/share/texlive/texmf-dist/tex/latex/tools/calc.sty)
(/usr/share/texlive/texmf-dist/tex/latex/eso-pic/eso-pic.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/share/texlive/texmf-dist/tex/latex/xcolor/xcolor.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics-cfg/color.cfg)
(/usr/share/texlive/texmf-dist/tex/latex/graphics-def/pdftex.def)
(/usr/share/texlive/texmf-dist/tex/latex/graphics/mathcolor.ltx)))
(/usr/share/texlive/texmf-dist/tex/latex/graphics/graphicx.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/share/texlive/texmf-dist/tex/latex/graphics-cfg/graphics.cfg)))
(/usr/share/texlive/texmf-dist/tex/latex/pdfpages/pppdftex.def))
(/usr/share/texlive/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def)
No file KV_2034__2021__ZR.margins.aux.
(/usr/share/texlive/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
) (/usr/share/texlive/texmf-dist/tex/latex/epstopdf-pkg/epstopdf-base.sty
(/usr/share/texlive/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg))
(/usr/share/texlive/texmf-dist/tex/latex/pdflscape/pdflscape.sty
(/usr/share/texlive/texmf-dist/tex/latex/pdflscape/pdflscape-nometadata.sty
(/usr/share/texlive/texmf-dist/tex/generic/iftex/iftex.sty)
(/usr/share/texlive/texmf-dist/tex/latex/graphics/lscape.sty))) [1 <./KV_2034__
2021__ZR.pdf>] [2 <./KV_2034__2021__ZR.pdf>] [3 <./KV_2034__2021__ZR.pdf>]
[4 <./KV_2034__2021__ZR.pdf>] [5 <./KV_2034__2021__ZR.pdf>] [6 <./KV_2034__2021
__ZR.pdf>] [7 <./KV_2034__2021__ZR.pdf>] [8 <./KV_2034__2021__ZR.pdf>] [9 <./KV
_2034__2021__ZR.pdf>] [10 <./KV_2034__2021__ZR.pdf>] [11 <./KV_2034__2021__ZR.p
df{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}>] [12 <./KV_2034__2021__Z
R.pdf>] (./KV_2034__2021__ZR.margins.aux)
Output written on KV_2034__2021__ZR.margins.pdf (12 pages, 1158174 bytes).
Transcript written on KV_2034__2021__ZR.margins.log.