Shell判断某文件夹下是否存在xxx开头的字符串


Usage: 

          bash judge_prefix_string.sh TARGET_DIR TARGET_STR

#!/bin/bash

TARGET_DIR=$1
TARGET_STR=$2

ls $TARGET_DIR/$TARGET_STR*
if [ $? -ne 0 ];then
    echo "file begin with $TARGET_STR is not existed!"
else
    echo "file begin with $TARGET_STR is existed!"
fi

for f in `ls $TAGET_DIR`;do
    if [[ "$f" =~^"$TARGET_STR".* ]]; then
        echo "file existed!"
    else
        echo "file not existed!"
    fi
done

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM