【问题标题】:moving files to their original locations after conversion转换后将文件移动到其原始位置
【发布时间】:2020-06-01 07:22:04
【问题描述】:

我创建了一个 Bash 脚本来将文件从 .odt 转换为 .pdf,但转换后,该脚本会将文件移动到当前工作目录中。由于脚本重复出现,我希望每个输出文件都保留在原始文件所在的位置。这是脚本。

#!/bin/bash
​
for file in $(find -type f -name '*.odt')
do
    echo $file
    libreoffice --headless --convert-to pdf $file
done

​我尝试将--outdir 设置为目录路径,但它将所有文件移动到这些目录。我希望转换后的文件与原始文件位于同一目录中。 ​

【问题讨论】:

  • 请先将您的脚本粘贴到那里,以提前消除大问题:shellcheck.net

标签: linux bash libreoffice


【解决方案1】:

动态生成--outdir 值,避免解析find 的输出。

find . -type f -name '*.odt' -print -exec sh -c '
for fpath do
  soffice --headless --convert-to pdf --outdir "${fpath%/*}" "$fpath"
done' _ {} +

【讨论】:

    猜你喜欢
    • 2021-08-19
    • 1970-01-01
    • 2018-12-11
    • 2014-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-06
    相关资源
    最近更新 更多