shell find: command not found

#!/bin/sh
#author  : pengzhi
#brief   : 批量转换文件到 指定编码
#todo    : 优化升级 方向 自动检查文件类型 转换到统一的目标类型
PATH=`pwd`
NAME=""
FROM_ENCODE="GBK"
TO_ENCODE="UTF-8"

function help()
{
    echo "Usage : sh iconv.sh -p <path> -n <name> -f <from_encode> -t <to_encode>"
    echo "e.g.  : sh iconv.sh     Iconv ./ all files from gbk to utf8"
    echo "e.g.  : sh iconv.sh -p ./ -n *.php  Iconv ./*php from gbk to utf8"
}
function main()
{
    for i in `find "${PATH}"  -type f -name "${NAME}"`;
    do  
        echo $i 
        echo ${i}.tmp   
        /usr/bin/iconv -f ${FROM_ENCODE} -t ${TO_ENCODE}  $i>${i}.tmp
        /bin/mv ${i}.tmp $i;                 
    done         
}
while getopts "p:n:f:t:h" opt
do
    case $opt in
        p)echo "opt=p arg=${OPTARG}";
        PATH=$OPTARG;;
        n)echo "opt=n arg=${OPTARG}";
        NAME=$OPTARG;;
        f)echo "opt=f arg=${OPTARG}";
        FROM_ENCODE=$OPTARG;;
        t)echo "opt=t arg=${OPTARG}";
        TO_ENCODE=$OPTARG;;
        h)echo "opt=h"
        help;
        exit 1;;
        ?)echo "opt=?"
        help;
        exit 1;;
        *)echo "opt=*"
        help;
        exit 1;;
    esac

done

if [[ $NAME"x" == "x" ]];then
    help;
    exit 1;
fi
if [[ $PATH"x" == "./x" ]];then
    PATH=`pwd`
fi
echo "*****************************************";
echo "PATH               :    ${PATH}";
echo "NAME               :    ${NAME}";
echo "FROM_ENCODE        :    ${FROM_ENCODE}";
echo "TO_ENCODE          :    ${TO_ENCODE}";

main;

echo "Finished";




原因分析 PATH变量覆盖了 系统默认的环境变量PATH导致

相关文章
相关标签/搜索