아래와 같이 쉘 변수에 저장 한 xml이 있습니다.
file1=$(sudo curl --silent -XGET 'https://<username>:<token>@dev-pilot.us-central1.gcp.dev.amazon.com/te-ci-9414/job/teserv-ci-9414_FSS_functional_test_develop-test_2/Report_20for_20FS/testng-results.xml')
echo $file1 // It prints expected xml file.
// 아래와 같이 위의 변수에서 @Total을 가져 오려고합니다.
total=$(xmllint --xpath "/testng-results/@total" $file1 |sed 's/"//g' | sed 's/^/"/' |sed 's/$/"/')
그러나 아래 오류 메시지가 반환되었습니다.
20:27:14 /tmp/jenkins4105200679331055571.sh: line 22: /usr/bin/xmllint: Argument list too long
xml 파일이 너무 커서 해당 파일을 살펴보고있는 부분을 방금 언급했습니다.
<?xml version="1.0" encoding="UTF-8"?>
<testng-results skipped="0" failed="7" total="2952" passed="2945">
누구든지 @total 속성 값을 가져 오는 데 도움을 줄 수 있습니까?
$file1
xmllint 명령 줄에서 사용할 때 xmllint는 xml이 명령 줄 인수의 무리라고 생각합니다.
대신 할 수있는 것은 -
xmllint에 입력이 stdin에서 온 것임을 알리고 <<<
XML을 제공하기 위해 "Here String"( )을 사용하는 것입니다.
(참고 : Windows에서 cygwin을 사용하여 테스트되었습니다.)
#!/usr/bin/env bash.exe
file1='<testng-results skipped="0" failed="7" total="2952" passed="2945"/>'
total=$(xmllint --xpath "/testng-results/@total" - <<<"$file1")
echo $total
산출:
total="2952"
sed 파이프가 무엇을 수행하고 있는지 확실하지 않지만 값 ( 2952
)을 원한다면 string()
xpath에서 사용할 수 있습니다 ...
--xpath "string(/testng-results/@total)"
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다