动手写了一个来看下 还不错
先来写bash个模块 判断文件是否存在 存在'Prompt' 不存在'mkdir'
vim check_Files.sh
#!/bin/bash #批量判断目录是否存在! function check{ ALL_LENGTH=80 STR=$1 LENGTH=${#STR} let RES=$ALL_LENGTH-$LENGTH echo -n $1 for((i=0;i<$RES;i++));do echo -n "." done if [ -d $1 ]; then echo -e "\E[1;31m 已经存在\E[0m" else mkdir -p $1 echo "创建成功" fi }
在来写一个bash 调用 check_Files.sh
vim name_files.sh
#!/bin/bash #导入脚本模块 check_Files.sh source ./check_Files.sh #调用模块方法测试files check "/home/chen" check "/var/httpd" check "etc/nginx"
sh name_files.sh
#!/bin/bash
#定义颜色的变量
RED_COLOR='\E[1;31m' #红
GREEN_COLOR='\E[1;32m' #绿
YELOW_COLOR='\E[1;33m' #黄
BLUE_COLOR='\E[1;34m' #蓝
PINK='\E[1;35m' #粉红
RES='\E[0m'
#需要使用echo -e 示例
echo -e "${RED_COLOR}======red color======${RES}"
echo -e "${YELOW_COLOR}======yelow color======${RES}"
echo -e "${BLUE_COLOR}======green color======${RES}"
echo -e "${GREEN_COLOR}======green color======${RES}"
echo -e "${PINK}======pink color======${RES}"