我将从bash运行的ssh命令的输出存储在一个变量中,我试图解析它并使用IFS获取最后一个值,但它一直忽略来自Qt应用程序的部分。 这是我所做的:
#!/bin/bash
results=$(ssh remote 'dbus-send --system --print-reply --type=method_call --dest=com.something.SomeApp /SomeApp com.something.SomeApp.status' 2>&1)
echo $results
IFS=$' ' # space is set as delimiter
read -ra ADDR <<< "$results" # results are read into an array as tokens separated by IFS
for i in "${ADDR[@]}"; do # access each element of array
printf '%s\n' "$i"
done
输出:
method return time=1570704023.543658 sender=:1.13063 -> destination=:1.14063 serial=5451 reply_serial=2 string "Idle"
method
return
time=1570700627.183948
sender=:1.13063
->
destination=:1.13308
serial=1183
reply_serial=2
它不见了:
string
和"Idle"
。
如果我复制在终端中获得的输出,则将其粘贴到bash脚本中,并在其上运行IFS,如下所示:
#!/bin/bash
manual="method return time=1570703114.770058 sender=:1.13063 -> destination=:1.13859 serial=4306 reply_serial=2 string "Idle""
IFS=$' ' # space is set as delimiter
read -ra ADDR <<< "$manual"
for i in "${ADDR[@]}"; do
printf '%s\n' "$i"
done
是否有一个隐藏的符号阻止IFS读取所有字符串,我如何实现将整个字符串放入数组的目标?