Shell I';我试图通过ssh连接到服务器来列出(ls)一个文件夹。是否有任何命令将输出存储为数组?
我尝试使用此命令Shell I';我试图通过ssh连接到服务器来列出(ls)一个文件夹。是否有任何命令将输出存储为数组?,shell,ssh,find,ls,Shell,Ssh,Find,Ls,我尝试使用此命令 array=`find ssh userName@Host ls 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=
array=`find ssh userName@Host ls 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
您可以使用
MYARRAY=(elem1 elem2 elem3)
符号在bash中创建数组
因此,它将是:
array=($(ssh userName@Host find Root/top/directory -type d))
嗨,玛菲,我不是shell的专家用户。你能解释一下吗?