以下代码行适用于我的数据库服务器 (unix)
xmllint --noout CI_PRD_TESTING.XML
但在 shell 脚本中同样不起作用
#!/bin/bash
export FOO="/home/data/others"
echo $FOO
vari=`ls -t1 CI_PRD*.XML | head -1`
xmllint --noout $vari
它给我以下错误。为什么会这样……
[testuser@mk-testdb others]$ bash validate_xml.sh
/home/data/others
"arning: failed to load external entity "CI_PRD_TESTING.XML
[testuser@mk-testdb others]$
最佳答案
非常感谢 Etan Reisner (https://stackoverflow.com/users/258523/etan-reisner) 通过评论部分本身为我提供了问题的答案。
写下答案,只是为了那些寻找答案而不是评论部分的人。
我的代码在每一行的末尾都有 ^M,
export FOO="/home/data/others"^M
echo $FOO^M
vari=`ls -t1 CI_PRD*.XML | head -1`^M
xmllint --noout $vari^M
使用以下命令后,它熄灭并按预期工作。
dos2unix validate_xml.sh
关于xmllint 在 shell 脚本中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33547874/