本脚本核心功能为,读取脚本数字后缀并传参到api中进行处理。可以理解为基于api的最基础的自动化测试脚本编写
#!/bin/bash
#liucheng_0.sh
SCRIPT_NAME=$(basename "$0")
echo "根据文件名序号自动传递不同的表情"
IFS='_' read -ra my_array <<< "$SCRIPT_NAME" #分割为 liucheng 0.sh
IFS='.' read -ra my_array2 <<< "${my_array[1]}" #读取0.sh并分割为 0 sh
curl -H 'content-type:application/json' -d '{"status": 1}' -i -X POST 'http://127.0.0.1:9981'
sleep 10
curl -H 'content-type:application/json' -d '{"status": 0}' -i -X POST 'http://127.0.0.1:9981'
sleep 1
curl -H 'content-type:application/json' -d "{\"status\": ${my_array2[0]}}" -i -X POST 'http://127.0.0.1:9981' #取出0使用
sleep 2
sh ../tool.sh #执行其他操作