#!/bin/bashapache
sum=0bash
for i in {1..100}; do
if [ $[$i%3] -eq 0 ]; then sum=$[$sum+$i] fi done
echo "sum=$sum"
1. 計算 100 之內全部能被 3 整除的整數之和react
#!/bin/bashapache
sum=0bash
for i in {1..100}; do
if [ $[$i%3] -eq 0 ]; then sum=$[$sum+$i] fi done
echo "sum=$sum"
2. 編寫腳本,求 100 之內全部正奇數之和curl
#!/bin/bash
#求100之內的奇數和函數
echo 計算出1-100的奇數之和 sum=0 for i in $(seq 1 2 100) do let sum+=i done echo $sum
3. 隨機生成 10 之內的數字,實現猜字遊戲,提示比較大或小,相等則退出url
#!/bin/bash
#隨機生成10之內的數字,實現猜字遊戲spa
read -p "請輸入一個10之內數字: " NU
if [ $NU -gt $[$RANDOM%10] ];then遊戲
echo "數字比較大"
elif [ $NU -eq $[$RANDOM%10] ];then
exit
elif [ $NU -lt $[$RANDOM%10] ];then
echo "數字過小了"
fiip
4. 編寫函數,實現兩個數字作爲參數,返回最大值ssl
#!/bin/bash
# 比較兩個數大小,返回最大值
max_num () {
if [ $1 -gt $2 ];then
echo "Max is $1"
else
echo "Max is $2"
fi
}
max_num $*
5. 編寫一個httpd安裝腳本
#!/bin/bash
#一鍵安裝httpd
#配置yum源和epel源
rm -rf /etc/yum.repos.d/*
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean al
yum makecache
yum repolist
#下載httpd源碼包
curl -o /opt/httpd-2.4.43.tar.bz2 https://mirror.bit.edu.cn/apache/httpd/httpd-2.4.43.tar.bz2
ls /opt
#安裝解壓賴包
yum -y install bzip2
#安裝httpd依賴包
yum install -y gcc make apr-devel apr-util-devel pcre-devel openssl-devel redhat-rpm-config
#建立apache用戶
useradd -r -u 48 -s /sbin/nologin -c "Apache" -d /var/www/ apache
cd /opt/ && tar -xjvf httpd-2.4.43.tar.bz2 -C /usr/local
cd /usr/local
./configure --prefix=/usr/local/httpd --sysconfdir=/etc/httpd --enable-ssl
make && make install
if [ $? -eq 0 ] ;then echo "httpd installed successful!"
fi