shell常用简单的几个脚本案列
1.打印形状
等腰三角形
read -p "Please input the length: " n
for i in seq 1 $n
do
for ((j=$n;j>i;j–))
do
echo -n " "
done
for m in seq 1 $i
do
echo -n "* "
done
echo
done
倒直角三角形
read -p "Please input the length: " len
for i in seq 1 $len
do
for j in seq $i $len
do
echo -n "* "
done
echo
done
直角三角形
read -p "Please input the length: " len
for i in seq 1 $len
do
for((j=1;j<=$i;j++))
do
echo -n "* "
done
echo
done
菱形
read -p "Please input the length: " n
for i in seq 1 $n
do
for ((j=$n;j>i;j–))
do
echo -n " "
done
for m in seq 1 $i
do
echo -n "* "
done
echo
done
for i in seq 1 $n
do
for((j=1;j<=i;k<=$len-1;k++))
do
echo -n "* "
done
echo
done
【脚本2】截取字符串
现有一个字符串如下:
http://www.aaa.com/root/123.htm
请根据以下要求截取出字符串中的字符:
1.取出www.aaa.com/root/123.htm
2.取出123.htm
3.取出http://www.aaa.com/root
4.取出http:
5.取出http://
6.取出www.aaa.com/root/123.htm
7.取出123
8.取出123.htm
#!/bin/bash
var=“http://www.aaa.com/root/123.htm”
#1.
echo $var |awk -F ‘//’ ‘{print $2}’
#2.
echo $var |awk -F ‘/’ ‘{print $5}’
#3.
echo $var |grep -o ‘http.*root’
#4.
echo $var |awk -F ‘/’ ‘{print $1}’
#5.
echo $var |grep -o ‘http://’
#6.
echo $var |grep -o ‘www.*htm’
#7.
echo $var |grep -o ‘123’
3.【脚本3】tomcat启动脚本