【发布时间】:2015-03-07 18:42:59
【问题描述】:
我想将一个 dbus 输出存储到一个数组中。
dbus-send --system --print-reply --dest="com.ac.comp" /com/ac/comp/IO com.ac.comp.Time.Get
当我执行上述命令时,我得到以下输出:
method return sender=:1.191 -> dest=:1.198 reply_serial=2
uint16 1
uint16 0
uint16 0
uint32 0
我的 bash 实现如下:
if [ -f $file ]
then
IFS=".="
while read enum name ID x
do
if [ "$enum" == "IO" ] && [ "$name" == $IOname ]
then
array=($(dbus-send --system --print-reply --dest="com.ac.comp" /com/ac/comp/IO com.ac.comp.IO.Get uint16:16))
fi
done < $1
else
exit_error
fi
我无法解释为什么下面的回显命令:
echo ${array[1]}
echo
echo ${array[2]}
echo
echo ${array[3]}
echo
echo ${array[4]}
echo
echo ${array[5]}
echo
echo ${array[6]}
echo
echo ${array[7]}
echo
echo ${array[8]}
echo
echo ${array[9]}
echo
echo ${array[10]}
echo
echo ${array[11]}
echo
echo ${array[12]}
echo
echo ${array[13]}
给了
:1
105 -> dest
:1
112 reply_serial
2
uint16 1
uint16 0
uint16 0
uint32 0
我想重用 uint16 和 uint32 值。但我虽然在 ${array[7]} ${array[9]} ${array[11]} 和 ${array[13]}
【问题讨论】:
-
如果将
dbus-send输出通过管道传输到hexdump或xxd会得到什么? -
对不起,Etan,但我该如何测试这些输出
-
嗯?我要你告诉我们,如果你这样做,你会得到什么。这样我们就可以看到 shell 在将输出拆分到数组时看到的内容。或者你的意思是如何做到这一点?
dbus-send ... | xxd -
我刚刚编辑了主帖。这就是将数据存储到数组中的方式。这不是正常行为..
-
如果您的
IFS设置为.,这是正常的。
标签: arrays bash return-value dbus