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
勤苦修行得自在,道力有边边亦无边!