开发者

I'm trying to list(ls) a folder by ssh-ing into a server. Is there any command to store the output as array?

I'm tried using this command

array=`find ssh userName@Host ls Roo开发者_如何学Got/top/directory -type d`

but it's stored only as a single variable instead of array.


you can use the MYARRAY=(elem1 elem2 elem3) notation for creating an array in bash.

So it will be:

array=($(ssh userName@Host find Root/top/directory -type d))


Split it up with awk or cut and then iterate over your array variable with an integer. Since ls prints on new lines, you can just loop.

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


Creating array from listing of files in directory

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜