xmllint --xpath '//tunnel_type/type/text()' config.xml 在脚本中判断这个结果等于35
时间: 2023-12-07 11:02:29 浏览: 47
您可以使用以下 Bash 脚本,将 xmllint 命令的输出结果存储到变量中,然后使用条件语句判断该变量是否等于 35:
```
#!/bin/bash
# Run xmllint command and save output to variable
tunnel_type=$(xmllint --xpath '//tunnel_type/type/text()' config.xml)
# Check if tunnel_type is equal to 35
if [ "$tunnel_type" -eq 35 ]; then
echo "tunnel_type is 35"
else
echo "tunnel_type is not 35"
fi
```
请注意,此脚本假定您已经有一个名为 `config.xml` 的文件,并且该文件包含一个名为 `tunnel_type` 的元素,其中包含一个名为 `type` 的子元素,该子元素的文本内容为数字 35。如果您的 XML 文件结构不同,您需要相应地更改 XPath 表达式。
相关问题
linux系统内配置xml文件中用shell脚本读取一个 <tunnel_types> <tunnel_type> <type>35</type> </tunnel_type></tunnel_types> 输出type的值
可以使用命令行工具xmllint和xpath来读取XML文件中的值。假设XML文件名为config.xml,可以使用以下命令来输出type的值:
```
xmllint --xpath '//tunnel_type/type/text()' config.xml
```
这个命令会在XML文件中查找所有tunnel_type节点下的type节点,并输出它们的值。如果只想输出第一个type节点的值,可以使用以下命令:
```
xmllint --xpath '//tunnel_type[1]/type/text()' config.xml
```
val=`xmllint --xpath "//tuningCustom[sensorDev=\"${t}\" and part=\"${p}\"]/${key}/text()" ${tuning_custom}`
这是一个在 Linux 命令行中使用 xmllint 解析 XML 文件的命令,其作用是获取 `${tuning_custom}` 文件中符合条件的 XML 节点中 `${key}` 元素的值,并将该值赋给变量 `${val}`。
具体来说,该命令中的选项 `--xpath` 表示使用 XPath 表达式来定位 XML 节点,`${t}` 和 `${p}` 是脚本中定义的变量,`${key}` 是需要获取的 XML 元素名,`${tuning_custom}` 是需要解析的 XML 文件名。
该命令的执行结果将被赋值给 `${val}` 变量,`${val}` 的值就是 `${tuning_custom}` 文件中符合条件的 XML 节点中 `${key}` 元素的值。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)