Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell I';我试图通过ssh连接到服务器来列出(ls)一个文件夹。是否有任何命令将输出存储为数组?_Shell_Ssh_Find_Ls - Fatal编程技术网

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的专家用户。你能解释一下吗?