本人菜鸡,请教一个 shell 脚本问题
資深大佬 : weichengwu 18
需求:从一段文本中提取字符串拼装并返回
原始文本:
+ fir p build/Runner.ipa -T $FIR_TOKEN I, [2020-08-17T18:31:29.047488 #39460] INFO -- : Fetching [email protected] uploading info...... I, [2020-08-17T18:31:29.047540 #39460] INFO -- : Uploading app: Runner-1.0.0(Build 1) I, [2020-08-17T18:31:29.209935 #39460] INFO -- : Publishing app via xxx<[email protected]>....... I, [2020-08-17T18:31:29.209980 #39460] INFO -- : ✈ -------------------------------------------- ✈ I, [2020-08-17T18:31:29.209991 #39460] INFO -- : begin to upload ... D, [2020-08-17T18:31:29.210023 #39460] DEBUG -- : begin to upload icon D, [2020-08-17T18:31:29.210159 #39460] DEBUG -- : icon_url = https://fir-app-icon.oss-cn-beijing.aliyuncs.com/8dff2f7f2lf0aa7cd1d2314cc09d6375db7bf239, icon_info = #<File:0x00007fd81db5c578> D, [2020-08-17T18:31:29.405214 #39460] DEBUG -- : begin to callback api D, [2020-08-17T18:31:29.486529 #39460] DEBUG -- : callback api finished D, [2020-08-17T18:31:29.486567 #39460] DEBUG -- : upload icon finished D, [2020-08-17T18:31:29.486579 #39460] DEBUG -- : begin to upload binary ... D, [2020-08-17T18:31:29.486692 #39460] DEBUG -- : binary_url = https://fir-app-binary.oss-cn-beijing.aliyuncs.com/15f4fdf09fee89137ca42d377903cb9jfc325a75, binary_info = #<File:0x00007fd81b8c9f60> D, [2020-08-17T18:31:29.486714 #39460] DEBUG -- : {"CONTENT-DISPOSITION"=>"attachment; filename* = UTF-8''Runner.ipa", "Content-Type"=>"application/octet-stream", "date"=>"Mon, 17 Aug 2020 10:31:29 GMT", "x-oss-date"=>"Mon, 17 Aug 2020 10:31:29 GMT", "authorization"=>"OSS xxx"} D, [2020-08-17T18:33:01.875110 #39460] DEBUG -- : begin to callback api D, [2020-08-17T18:33:02.798259 #39460] DEBUG -- : callback api finished D, [2020-08-17T18:33:02.798294 #39460] DEBUG -- : upload binary ... finished I, [2020-08-17T18:33:02.798362 #39460] INFO -- : File uploaded. During: 93 seconds, Upload Speed: 2269 KB/s I, [2020-08-17T18:33:02.798376 #39460] INFO -- : App id is 582320e1calfs83366c7ayes I, [2020-08-17T18:33:02.798383 #39460] INFO -- : Release id is 5f3a5fhsb2eb489a96sadekl I, [2020-08-17T18:33:02.798409 #39460] INFO -- : Fetch app info from fir.im I, [2020-08-17T18:33:02.911772 #39460] INFO -- : end upload I, [2020-08-17T18:33:02.911811 #39460] INFO -- : ✈ -------------------------------------------- ✈ I, [2020-08-17T18:33:02.911835 #39460] INFO -- : Published succeed: http://d.firim.info/hspo I, [2020-08-17T18:33:05.827140 #39460] INFO -- :
需要找到 Published succeed:
所在行后面的内容,加上 Release id is
所在行后面的内容
拼装后的目标:
http://d.firim.info/hspo?release_id=5f3a5fhsb2eb489a96sadekl
附上我写的脚本:
#!/bin/bash fir_result=$(</dev/stdin) get_substr_after() { local match_line=$(grep "$1" <<< "$fir_result") echo ${match_line#*$1} } short_url=$(get_substr_after "Published succeed: ") release_id=$(get_substr_after "Release id is ") echo "${short_url}?release_id=${release_id}"
实际输出结果:
?release_id=5f3a5fhsb2eb489a96sadekl
short_url
是空的,请问哪里写错了?
大佬有話說 (3)