我正在尝试复制不同文件夹中的文件。文件夹名称在运行时动态更改。所以我试图将其保存在变量中并尝试复制。它的投掷错误。请你帮我解决一下
current_path : '/tmp/build/bf45481f'
brokerutils='/resource-app/ServiceBrokers/BrokerCommonUtils/*'
broker='/resource-app/ServiceBrokers/AuthServiceBroker_New/'
path_source="$current_path$brokerutils"
path_dest="$current_path$broker"
cp -R "${path_source}${path_dest}"
Path_dest:/tmp/build/bf45481f/resource-app/ServiceBrokers/AuthServiceBroker_New/
Path_source:/tmp/build/bf45481f/resource-app/ServiceBrokers/BrokerCommonUtils/BrokerRoutes.js /tmp/build/bf45481f/resource-app/ServiceBrokers/BrokerCommonUtils/DALAdapter.js /tmp/build/bf45481f/resource-app/ServiceBrokers/BrokerCommonUtils/gistdb.js 的/ tmp /建造/ bf45481f /资源的应用程序/ ServiceBrokers / BrokerCommonUtils / middleLayer
错误:cp:丢失后的目标文件操作数 ' / TMP /构建/ bf45481f /资源的应用程序/ ServiceBrokers / BrokerCommonUtils / * / TMP /构建/ bf45481f /资源的应用程序/ ServiceBrokers / AuthServiceBroker_New /'
答案 0 :(得分:1)
使用shell脚本将文件从1个文件夹复制到另一个文件夹名称是动态的简单示例
!/bin/bash
echo "Enter sourc path:"
read sourc
echo "Enter dest path:"
read dest
path_source="$sourc"
path_dest="$dest"
cp -rf $path_source $path_dest
答案 1 :(得分:0)
我认为错误少了一个:你错过$ {path_source}和$ {path_dest}之间的空格。
试试cp -R "${path_source} ${path_dest}"