您现在的位置是:主页 > news > 江苏科技大学新校区建设网站/百度推广的方式有哪些
江苏科技大学新校区建设网站/百度推广的方式有哪些
admin2025/4/22 3:50:04【news】
简介江苏科技大学新校区建设网站,百度推广的方式有哪些,网站做流量怎么赚钱的,门户网站模式函数概念 shell中允许将一组命令集合或语句形成一段可用代码,称为shell函数给这段代码七个名字称为函数名,后续可以直接调用该段代码的功能 函数定义 方法一函数名(){函数体(一堆命令的集合,来实现某个功…
江苏科技大学新校区建设网站,百度推广的方式有哪些,网站做流量怎么赚钱的,门户网站模式函数概念
shell中允许将一组命令集合或语句形成一段可用代码,称为shell函数给这段代码七个名字称为函数名,后续可以直接调用该段代码的功能
函数定义
方法一函数名(){函数体(一堆命令的集合,来实现某个功…
函数概念
- shell中允许将一组命令集合或语句形成一段可用代码,称为shell函数
- 给这段代码七个名字称为函数名,后续可以直接调用该段代码的功能
函数定义
方法一函数名(){函数体(一堆命令的集合,来实现某个功能)}方法二function 函数名(){函数体(一堆命令的集合,来实现某个功能)echo helloecho world}
函数练习:有颜色的字符串输出
1.要求
- 输出具有不同颜色的
hello world
2.代码及思路分析
RED="\033[31m"
GREEN="\033[32m"
YELLOW="\033[33m"
END="\033[0m"print_color_string(){color=$1string=$2case $color inred)echo -e "$RED $string $END";;green)echo -e "$GREEN $string $END";;yellow)echo -e "$YELLOW $string $END";;*)echo $string;;esac
}print_color_string 'red' 'hello world'
print_color_string 'green' 'hello world'
print_color_string 'yellow' 'hello world'
print_color_string ' ' 'hello world'
3.结果
调用函数完成:nfs配置文件的有颜色报错
1.要求
- 使用shell脚本自动搭建 nfs 服务之前的报错信息是白色的,而使用函数可完成有颜色的字符串输出
- 结合函数使我们完成nfs中红色报错信息;绿色的完成信息
2.代码
#!/bin/bashRED="\033[31m"
GREEN="\033[32m"
YELLOW="\033[33m"
END="\033[0m"print_color_string(){color=$1string=$2case $color inred)echo -e "$RED $string $END";;green)echo -e "$GREEN $string $END";;yellow)echo -e "$YELLOW $string $END";;*)echo $string;;esac
}[ `id -u` -eq 0 ] || {print_color_string 'red' 'Error: This script must run as root!'exit 1
}[ $# -eq 2 ] || {print_color_string 'red' 'Error: please input userfile and passwordfile'exit 1
}[ -f $1 ] || {print_color_string 'red' 'Error: userfile not exits'exit 1
}[ -f $2 ] || {print_color_string 'red' 'Error: passwordfile not exits'exit 1
}
users_line=`wc -l $1 | cut -d' ' -f1`
pwds_line=`wc -l $2 | cut -d' ' -f1`
[ $users_line != $pwds_line ] && {print_color_string 'red' 'userfile lines is differ passwordfile'exit 1
}max_line=`wc -l $1 | cut -d' ' -f1`
for num in `seq 1 $max_line`
doecho '------------------------'username=`sed -n ${num}p $1`password=`sed -n ${num}p $2`useradd $usernameif [ $? -eq 0 ];thenecho "$username Create success";echo $password | passwd --stdin $usernameprint_color_string 'green' 'username set password success'elseeco "$username Create failed"fi
done
3.结果
- 红色报错信息
- 绿色成功信息