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

  

posted @ 2019-07-09 19:23  无边身尊者  阅读(3713)  评论(0编辑  收藏  举报