版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_37413035/article/details/82657939
Shell 脚本(shell script),是一种为 shell 编写的脚本程序,业界所说的 shell 通常都是指 shell 脚本。(区分于shell,shell 和 shell script 是两个不同的概念。Shell 是一个用 C 语言编写的程序,它是用户使用 Linux 的桥梁。Shell 既是一种命令语言,又是一种程序设计语言。用户通过Shell这种应用程序提供的界面来访问操作系统内核的服务)
Shell脚本编程常用例子
#/bin/bash
threadCount=`cat count`;
topic=`cat topic`
#echo $topic
#访问文件中每行的数据
for redis in $(cat redis.list); do
echo $redis
host=`echo $redis | awk -F ":" '{print $1}'`
port=`echo $redis | awk -F ":" '{print $2}'`
#echo $host
#echo $port
#shell for循环
#for i in {1..50}; do
for (( index=0; index<$threadCount; index++ )); do
queueName=hehe-haha-$topic-2.2.2.223-$index
queueName2=hehe-haha-$topic-2.2.2.223-$index
#echo $queueName
result=`redis-cli -h $host -p $port zcard $queueName`
#echo $result
# shell if判断
if [ "$result" != "0" ]; then
echo "redis: $redis queue: $queueName length is $result "
zrangeResult=`redis-cli -h $host -p $port zrange $queueName 0 -1 withscores`
echo $zrangeResult
#shell中的字符串按照空格分割存到数组中
#array=(${zrangeResult})
# 数组的长度
#num=${#array[@]}
#for ((i=0; i<num;)); do
# value=${array[i]}
# i=$((i+1))
# score=${array[i]}
# i=$((i+1))
# redis-cli -h $host -p $port zadd $queueName2 $score $value
#done
fi
done
done
学习资料:
1.https://blog.csdn.net/china1000/article/details/45675863
2.https://www.jb51.net/article/28514.htm