Bash%d从0开始,我可以从1开始

时间:2022-06-19 20:46:39

I'm using python and have the following command.

我正在使用python并具有以下命令。

subprocess.Popen(['convert '+document+' '+outFile+'_page%04d.tif'],
                 stdout=subprocess.PIPE, shell=True).wait()

It works fine, except I end up with my output as XXX_page0000.tif as my first page, then numbering up.

它工作正常,除了我的输出结果为XXX_page0000.tif作为我的第一页,然后编号。

Is it possible to get the %04d in bash to start at 1 instead of 0.

是否有可能让bash中的%04d从1开始而不是0。

So that my first output file is XXX_page0001.tif ?

所以我的第一个输出文件是XXX_page0001.tif?

1 个解决方案

#1


%d is not handled by bash, its handled by imagemagicks convert.

%d不是由bash处理的,它由imagemagicks转换处理。

You can specify the starting number using -scene, so you could do:

您可以使用-scene指定起始编号,因此您可以执行以下操作:

subprocess.Popen(['convert -scene 1 '+document+' '+outFile+'_page%04d.tif'],
             stdout=subprocess.PIPE, shell=True).wait()

#1


%d is not handled by bash, its handled by imagemagicks convert.

%d不是由bash处理的,它由imagemagicks转换处理。

You can specify the starting number using -scene, so you could do:

您可以使用-scene指定起始编号,因此您可以执行以下操作:

subprocess.Popen(['convert -scene 1 '+document+' '+outFile+'_page%04d.tif'],
             stdout=subprocess.PIPE, shell=True).wait()