【发布时间】:2011-10-16 03:47:43
【问题描述】:
我尝试使用此命令
array=`find ssh userName@Host ls Root/top/directory -type d`
但它只存储为单个变量而不是数组。
【问题讨论】:
我尝试使用此命令
array=`find ssh userName@Host ls Root/top/directory -type d`
但它只存储为单个变量而不是数组。
【问题讨论】:
您可以使用MYARRAY=(elem1 elem2 elem3) 表示法在 bash 中创建数组。
原来是这样:
array=($(ssh userName@Host find Root/top/directory -type d))
【讨论】:
使用 awk 或 cut 将其拆分,然后使用整数迭代数组变量。由于 ls 在新行上打印,您可以循环。
array=find ssh userName@Host ls Root/top/directory -type d
i=0
echo array | while read LINE;
do
myarray=${LINE[$i]}
i=$((i+1))
done
【讨论】: