2017-10-16 54 views
-1

我使用rsync將rep1中的文件複製到rep2。我用getopt來創建一個調用這個函數的參數。該函數被調用的情況下,但做一個無限循環,我不知道爲什麼。我在沒有大小寫的情況下嘗試了這個函數,它運行得很好Infini在使用rsync的腳本上循環使用

東西在rsync的():

read -p 'Enter source directory : ' repSource 
    read -p 'Enter destination directory : ' repDest 


    if [ -e $repSource ] && [ -d $repSource ] && [ -e $repDest ] && [ -d $repDest ] 
    then 
      echo "File exists and it is a directory !" 
      echo "Synchronisation of " $repSource "to " $repDest 
      rsync -av $repSource $repDest 


    else 

      echo "File doesn't exit or it is not a directory !" 
    fi 

這裏我的情況:

OPTS=$(getopt -o h,m,p,a,l,t) 
if [ $? != 0 ] 
then 
    exit 1 
fi 

    case "$1" in 

      -h) aide; 
       exit 0;; 
      -m) RAM; 
       exit 0;; 
      -p) CPU; 
       exit 0;; 
      -a) logcpu; 
       exit 0;; 
      -l) autolog; 
       exit 0;; 
      -t) rsync; 
       exit 0;; 
    esac 

下面的結果:

Enter source directory : rep1/ 
Enter destination directory : rep2/ 
File exists and it is a directory ! 
Synchronisation of rep1/ to rep2/ 
Enter source directory : 

感謝您的幫助!

+0

有沒有人告訴你,命名shell函數是真正的命令是一個非常糟糕的主意?殼牌是一種難以使用的語言,我不會推薦它用於新手。 – 0andriy

+0

使用'-e'是多餘的;如果參數不存在,'-d'測試將失敗。 – chepner

回答

1

您正在使用您的同名函數遮蔽「真實」命令rsync。您可以保留rsync作爲函數名稱,但是您需要使用內置的command忽略該函數並調用真實命令。

command rsync -av "$repSource" "$repDest"