我正在編寫一個腳本,該腳本讀取文字文件,並使用文字檔案中儲存的資訊將輸入的每一行作為數組。該數組是對導入到另一個腳本中的目錄的檔案的引用。問題是我建立了一個函數來壓縮目錄的內容並更改其所有權,但是當我運行腳本時,它正在壓縮並嘗試更改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[@}"/
最後.
導致了問題。