shell脚本 dos文件转unix 类似dos2unix命令

#! /bin/sh
dostype=dos
IFS=$(echo -en "\n\b")
function iterate_dir(){
for file in $1/*; do
if [ -f $file ]; then
typename=`file $file | grep -q CRLF && echo dos || echo unix`
if [[ $typename == $dostype ]]; then
sed -i "s/.$//g" $file
echo 'converting '$file
else
:
fi
else
iterate_dir $file
fi
done
}
if [ "$1" == "" ]; then
echo 'convering start'`pwd`
iterate_dir .
else
echo 'convering start'$1
iterate_dir $1
fi

你可能感兴趣的:(Linux)