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