【问题标题】:I'm trying to list(ls) a folder by ssh-ing into a server. Is there any command to store the output as array?我正在尝试通过 ssh-ing 到服务器来列出(ls)一个文件夹。有没有将输出存储为数组的命令?
【发布时间】:2011-10-16 03:47:43
【问题描述】:

我尝试使用此命令

array=`find ssh userName@Host ls Root/top/directory -type d`

但它只存储为单个变量而不是数组。

【问题讨论】:

    标签: shell ssh find ls


    【解决方案1】:

    您可以使用MYARRAY=(elem1 elem2 elem3) 表示法在 bash 中创建数组。

    原来是这样:

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

    【讨论】:

      【解决方案2】:

      使用 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
      

      【讨论】:

      • 嗨,malfy,我不是 shell 专家。你能解释一下吗?
      【解决方案3】:
      猜你喜欢
      • 2019-07-12
      • 1970-01-01
      • 2012-06-06
      • 2011-06-08
      • 2014-08-09
      • 1970-01-01
      • 2023-03-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多