首页 > 解决方案 > 如何对同一目录中的多个文件执行 dos2unix 命令?

问题描述

我试过-name: convert files to Unix format command: dos2unix "{{ scripts_dir }}/*.sh"</p>

它说dos2unix:转换文件时出现问题。完全相同的命令在 shell 中工作。我只想知道是否有更快的方法而不是使用循环(with_items 或 with_fileglob)。

命令:dos2unix “{{ item }}” with_fileglob: - “{{ scripts_dir }}/*.sh”</p>

以上是我拥有的当前工作版本。

标签: ansible

解决方案


通过使用“命令”,您只需执行一个命令。但是您正在使用通配符(*)。这是由一个shell 完成的,即bash。所以你应该使用 shell 模块:

- name: Execute dos2unix on several files
  shell: dos2unix “{{ scripts_dir }}/*.sh"
  args:
    chdir: "/home/yourdir/"

推荐阅读