![用于压缩文件并更改其所有权的脚本](https://linux22.com/image/38446/%E7%94%A8%E4%BA%8E%E5%8E%8B%E7%BC%A9%E6%96%87%E4%BB%B6%E5%B9%B6%E6%9B%B4%E6%94%B9%E5%85%B6%E6%89%80%E6%9C%89%E6%9D%83%E7%9A%84%E8%84%9A%E6%9C%AC.png)
我正在编写一个脚本,该脚本读取文本文件,并使用文本文件中存储的信息将输入的每一行作为数组。该数组是对导入到另一个脚本中的目录的文件的引用。问题是我构建了一个函数来压缩目录的内容并更改其所有权,但是当我运行脚本时,它正在压缩并尝试更改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[@}"/
最后.
导致了问题。