zoukankan      html  css  js  c++  java
  • .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}

  • 相关阅读:
    ThinkPHP5.0更改框架的验证方法:对象->validate(true)->save();
    ThinkPHP5.0版本和ThinkPHP3.2版本的区别
    ThinkPHP5.0版本的优势在于:
    11: django-haystack+jieba+whoosh实现全文检索
    10: supervisor进程管理工具
    09: redis集群之sentinel
    08: python支付宝支付
    07: redis分布式锁解决超卖问题
    06:keepalive高可用集群(新)
    05: 使用docker部署nginx负载均衡
  • 原文地址:https://www.cnblogs.com/shexunyu/p/14945969.html
Copyright © 2011-2022 走看看