Bash脚本常见用法

字符串中提取文件名,并赋值给变量

#提取文件名成功

projects="D:/Project/Program/IDEAWorkspace/myauto/automation-test/src/main/java/com/welab/automation/projects/channel/feature/abc.feature"

filename=${projects##*/} #变量赋值 等号两边不要空格

echo "${filename}" #abc.feature

上传feature使用的脚本

#!/bin/bash

zstoken="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjb250ZXh0Ijp7ImJhc2VVcmwiOiJodHRwczovL3dlbGFiYmFuay5hdGxhc3NpYW4ubmV0IiwidXNlciI6eyJhY2NvdW50SWQiOiI2Mjk4NzAxMDk1ODJiODAwNmZjNWI3ODAifX0sImlzcyI6ImNvbS5rYW5vYWgudGVzdC1tYW5hZ2VyIiwic3ViIjoiZmYzNWI4MzctNTIyOS0zZmFiLTgwM2UtN2EyN2ExMGFlZGVjIiwiZXhwIjoxNzAwMjAzMzEwLCJpYXQiOjE2Njg2NjczMTB9.qBPibMSKKtJJb9has09MEJXCpM4sd1pV6Ko0LDrYKLo"

#FILES="./zephyrScaleTestCase/*"

#for f in $FILES

#for f in ./zephyrScaleTestCase/*.feature ./zephyrScaleTestCase/**/*.feature

projects="D:/Project/Program/IDEAWorkspace/myauto/automation-test/src/main/java/com/welab/automation/projects"

for f in ${projects}/**/**/**/*.feature ${projects}/**/**/**/**/*.feature ${projects}/**/**/**/**/**/*.feature ${projects}/**/**/**/**/**/**/*.feature ${projects}/**/**/**/**/**/**/**/*.feature

do

fileName=$(basename $f)#just file name ##fn=$(sed 's/.*\///' <<< $f)alternative to filter filename from full path

dirName=$(dirname $f)#dir path

partialName=${f#${projects}}

#extension=${fileName##*.} #extension of file

##featureText=`cat $f` #for checking if the "Feature:" line is commented

featureText=`cat $f | tr '\r\n' "#"`

featureText=$(sed 's/@/#>/g' <<< $featureText)

featureText=$(sed 's/"/`>/g' <<< $featureText)

featureText=$(sed 's/\x27/`>/g' <<< $featureText)

featureText=$(sed 's/##/\<br\>/g' <<< $featureText)

echo "${partialName}"

echo "${fileName}"

if ! [[ $fileName = *"TAT-T"* ]]; then # if fileName doesn't contain "TAT-T"

#casename=${f##*/}

# echo "${casename}"

#create test case, save test case key

testCaseKey=$(curl -k -H "Authorization: Bearer ${zstoken}" -X POST "https://api.zephyrscale.smartbear.com/v2/testcases" -H "Content-Type: application/json" -d "{\"projectKey\":\"TAT\",\"name\":\"${partialName}\"}" | jq --raw-output '.key')# > choco install jq

#create test script

echo "${testCaseKey}"

curl -k -H "Authorization: Bearer ${zstoken}" -X POST "https://api.zephyrscale.smartbear.com/v2/testcases/${testCaseKey}/testscript" -H "Content-Type: application/json" -d "{\"type\":\"plain\",\"text\":\"${featureText}\"}"

#add test case key as prefix

mv -f "$f" "${dirName}/${testCaseKey}_${fileName}"

#write automated test case key and path to appendix

appendix=`cat ./zephyrScaleTestCase/appendix.json` #let initialize the content of appendix.json to be "[]" (omit the double quotes)

# need to revise test case key, path

echo $(jq --null-input --argjson a "$appendix" '$a + [{"autoTestCaseKey": "'${testCaseKey}'", "manualTestCaseKey": "", "path": "'${dirName}/${testCaseKey}_${fileName}'"}]') > ./zephyrScaleTestCase/appendix.json

fi

done

echo `cat ./zephyrScaleTestCase/appendix.json`

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值