2013-09-30 134 views
0

以下是在本地服务器在Linux上将不同扩展的文件从一台服务器传输到另一台服务器?

-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 

传输文件在我InputLocation的文件,但我试图把extns在一个变量如下

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

但我得到以下例外,虽然文件可用

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

请帮忙吗?

回答

0

说:

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 
相关问题