.sh文件格式问题dos转linux或unix

问题描述
 

 line 11: syntax error: unexpected end of file

查看文件格式
# :set ff?
fileformat=unix
安装转换工具
# yum install -y dos2unix
单个转换文件格式
# dos2unix restart_apiservice.sh
批量转换文件格式
#!/bin/bash

############################################################
# 用途:批量修改指定目录的sh文件格式为linux可执行格式
# 作者:xunyushe
# 时间:2021-06-28
############################################################



############################################################
# 用户自定义变量
############################################################

# 需要查询的目录
WorkDir=$(cd $(dirname $0); pwd)
if [ ! -n "$1" ] ;then
    echo "设置当前执行目录"
else
    echo "设置输入参数"
    WorkDir=$1
fi

InitPath=${WorkDir}
# 定义文件名后缀
FileType='sh'

############################################################
# 函数:递归获取指定目录下满足条件的文件及其路径
# 参数:$1,需要查询的目录
############################################################
function Set_File_Type(){
    for each in $(ls $1);do
        FilePath=${1}/${each}
        if [ -d ${FilePath} ];then
            # 如果文件是目录,则继续往里面查找
            Set_File_Type ${FilePath}
        else
            # 判断文件名称是否满足条件
            if [ "${FilePath##*.}"x = "${FileType}"x ];then
                dos2unix ${FilePath}
                echo "转换${FilePath}"            
            fi
        fi
    done
}

############################################################
# 入口
############################################################
# 执行函数
Set_File_Type ${InitPath}

原文地址:https://www.cnblogs.com/shexunyu/p/14945969.html