代码之家  ›  专栏  ›  技术社区  ›  user2531569

在linux上将不同扩展名的文件从一台服务器传输到另一台服务器?

  •  0
  • user2531569  · 技术社区  · 13 年前

    以下是本地服务器中我的InputLocation中的文件

    -rw-r----- 1 root root 0 Sep 25 15:03 one.xml
    -rw-r----- 1 root root 0 Sep 25 15:03 two.xml
    -rw-r----- 1 root root 0 Sep 25 15:03 data.csv
    -rw-r----- 1 root root 0 Sep 25 15:03 free.png
    -rw-r----- 1 root root 0 Sep 25 15:04 loaded.jpeg
    

    我可以使用以下命令传输文件

    scp ${InputPath}/*.{jpeg,xml} ${user}@${HostName}:$OutputPath
    

    但我正试图将extns放在一个变量中,如下所示

    FilesExtnsToBeTransfered=jpeg,xml
    scp ${InputLocation}/*.{$FilesExtnsToBeTransfered} ${user}@${HostName}:$OutputPath
    

    但我得到了以下例外,尽管文件是可用的

    InputLocation/*.{jpeg,xml}: No such file or directory
    

    请帮忙吗?

    1 回复  |  直到 13 年前
        1
  •  0
  •   devnull    13 年前

    说:

    FilesExtnsToBeTransfered=jpeg,xml
    echo {$FilesExtnsToBeTransfered}
    

    将导致 {jpeg,xml} ( 不会进行支架扩展 ).

    您有两种选择:

    1. (丑陋,不推荐):使用 eval .

      eval scp ${InputLocation}/*.{$FilesExtnsToBeTransfered} ${user}@${HostName}:$OutputPath

    2. 将所需的文件扩展名放入数组中:

    EXTNS=( jpeg xml )
    for i in "${EXTNS[@]}"; do
      scp ${InputLocation}/*.$i ${user}@${HostName}:$OutputPath
    done