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
来源:https://www.cnblogs.com/noxy/p/11159701.html