我正在编写一个脚本,该脚本读取文本文件,并使用文本文件中存储的信息将输入的每一行作为数组。该数组是对导入到另一个脚本中的目录的文件的引用。问题是我构建了一个函数来压缩目录的内容并更改其所有权,但是当我运行脚本时,它正在压缩并尝试更改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;
有没有人有什么建议?
答案1
发现问题了。问题在于zip -r ~/export/"${studyinstanceuids[@]}"/20140620_"${studyinstanceuids[@]}".zip .
我需要将其更改为zip -r ~/export/"${studyinstanceuids[@]}"/20140620_"${studyinstanceuids[@]}".zip ~/export/"${studyinstanceuids[@}"/
最后.
导致了问题。