我正在处理一个脚本,它读取文本文件,并使用文本文件中存储的信息将每行输入作为数组。此数组是对导入到另一个脚本中的目录的文件的引用。问题是我构建了一个函数来压缩目录的内容并更改它的所有权,但是当我运行脚本时,它正在压缩并尝试更改pwd
的所有权。以下是我的代码:
file=~/exporttool/zipFiles.txt
index=0
declare -a studyinstanceuids
while read line ; do
studyinstanceuids[$index]="$line"
index=$((index+1))
echo $line
done < $file
for i in "${studyinstanceuids[@]}"
do
echo "$i" | ./cmd2;
done
echo "Exams are in!";
##Function with argument that will take prompt to change ownerships
echo "What is the name of the owner: "
read $owner
zipForOwner(){
arg1=$1
for i in "${studyinstanceuids[@]}"; do
zip -r ~/export/"${studyinstanceuids[@]}"/20140620_"${studyinstanceuids[@]}".zip .
sudo chown $1:$1 ~/export/"${studyinstanceuids[@]}"/"${studyinstanceuids[@]}".zip
sudo mv ~/export/"${studyinstanceuids[@]}"/"${studyinstanceuids[@]}".zip ~/home/"$1"
done
}
zipForOwner $owner
exit;
有没有人有任何建议
编辑:Heere是我在xterm中运行的结果
+ file=/home/support/exporttool/zipFiles.txt
+ index=0
+ declare -a studyinstanceuids
+ read line
+ studyinstanceuids[$index]=1.3.46.670589.16.11.8.34254330145.20140603.134057.0
+ index=1
+ echo 1.3.46.670589.16.11.8.34254330145.20140603.134057.0
1.3.46.670589.16.11.8.34254330145.20140603.134057.0
+ read line
+ for i in '"${studyinstanceuids[@]}"'
+ echo 1.3.46.670589.16.11.8.34254330145.20140603.134057.0
+ ./cmd2
Please enter StudyInstanceUID:
+ echo 'Exams are in!'
Exams are in!
+ echo 'What is the name of the owner: '
What is the name of the owner:
+ read
sftpuser
+ zipForOwner
+ arg1=
+ for i in '"${studyinstanceuids[@]}"'
+ zip -r /home/support/export/1.3.46.670589.16.11.8.34254330145.20140603.134057.0/20140620_1.3.46.670589.16.11.8.34254330145.20140603.134057.0.zip .
adding: .studiesToExportSend.txt.swp^C
zip error: Interrupted (aborting)
+ sudo chown : /home/support/export/1.3.46.670589.16.11.8.34254330145.20140603.134057.0/1.3.46.670589.16.11.8.34254330145.20140603.134057.0.zip
[sudo] password for support:
答案 0 :(得分:0)
这一行是你的问题:
zip -r ~/export/"${studyinstanceuids[@]}"/20140620_"${studyinstanceuids[@]}".zip .
您正在尝试使用当前目录 ~/export/"${studyinstanceuids[@]}"/20140620_"${studyinstanceuids[@]}".zip
中的所有内容(不良)创建名为.
(好)的zip文件。
您需要将.
更改为要压缩的文件夹。