如何在文件名中包含带有“[ ]”的铸造文件

如何在文件名中包含带有“[ ]”的铸造文件

我使用 bash 生成文件列表并制作部分

git ls-files *js | 
while read  i; do                
    name=${i//\/\\/ }
    name=${name//_/\\_}             
    echo "\newpage" >> $tex_file 
    echo "\section{$name}" >> $tex_file 
    echo "\inputminted[linenos,tabsize=2,breaklines]{text}{'$i'}" >>$tex_file
done &&

并出现 pdglatex 错误

(/usr/share/texlive/texmf-dist/tex/latex/base/ts1cmtt.fd) [8] [9] [10] [11]
[12] [13]) [14]
Overfull \hbox (83.28297pt too wide) in paragraph at lines 36--36
|[]\T2A/cmr/bx/n/14.4 drafts/zakaz/CustomerOrdersExchange/parsers/InformationRe
gisterRecord.js|
(./_minted-tmp/42C1FB8BAA58B770CBB63CD3829666B6.pygtex [15]) [16]sh: 1: Syntax error: Unterminated quoted string
system returned with code 512


! Package minted Error: Missing Pygments output; \inputminted was
probably given a file that does not exist--otherwise, you may need
the outputdir package option, or may be using an incompatible build tool,
or may be using frozencache with a missing file.

See the minted package documentation for explanation.
Type  H <return>  for immediate help.
 ...

l.40 ...ext}{'server/api/1c/[shopid]/exchange.js'}

?

我需要[]文件名,因为https://nuxt.com/docs/guide/directory-structure/pages#dynamic-routes

答案1

当您处理文件名等时,其中包含分隔符或特殊字符(如括号、逗号等),您需要添加一对额外的括号来保护它们。

对于你的情况:

git ls-files *js | 
while read  i; do                
    name=${i//\/\\/ }
    name=${name//_/\\_}             
    echo "\newpage" >> $tex_file 
    echo "\section{$name}" >> $tex_file 
    echo "\inputminted[linenos,tabsize=2,breaklines]{text}{{'$i'}}" >>$tex_file
done &&

应该管用。

相关内容