我在一个目录中有许多*.c和*.h文件。我想把所有这些文件转换成Linux兼容的格式。我试图跟随脚本运行,但是没有任何东西被转换。
我还需要检查是否一切都被成功地转换了。因此,我过滤并比较它的输出与目录中的原始文件。
我怎么才能修好它?
#!/bin/bash
function converting_files() {
cd "/path/to/dir" && find . -type f -print0 | xargs -0 | dos2unix
}
function success_of_converting_files() {
FILES=colsim_xfig/xfig.3.2.5c/*
#There are 250 files in the dir and not all but most of them are .c and .h
for i in {000..249} ; do
for f in "$Files" ; do
#I think *.txt line ending is fine as we only want to compare
dos2unix < myfile{i}.txt | cmp -s - myfile{i}.txt
done
done
}
function main() {
converting_files
success_of_converting
}我基本上需要将所有文件转换为LF行尾。p.S:目录中的文件总数是249。目录中的文件数量不是固定的,所以,如果我可以有任意数量的参数而不是249个参数,那就更好了。
发布于 2019-05-21 20:58:03
在命令中
cd "/path/to/dir" && find . -type f -print0 | xargs -0 | dos2unix您正在将一个空分隔的文件名列表传递给xargs,但没有提供在它们上运行的命令。在本例中,xargs默认对它们执行/bin/echo:换句话说,它只是在标准输出上输出一个以空格分隔的文件名列表,然后将其输送到dos2unix。结果不是将文件转换为Unix格式,而是转换文件名列表。
想必你的意图是
cd "/path/to/dir" && find . -type f -print0 | xargs -0 dos2unix但是,您可以使用find命令的-exec或-execdir实现同样的目标。
find "/path/to/dir/" -type f -execdir dos2unix {} +或(限制为.c和.h文件)
find "/path/to/dir/" -type f -name '*.[ch]' -execdir dos2unix {} +https://askubuntu.com/questions/1145136
复制相似问题