2012-03-20 15 views
0

ディレクトリ(エコー1)のすべてのファイルを、アーカイブディレクトリの[ディレクトリ名] .tarという名前のtarアーカイブにタールしようとしていますエコー)。これは正しいです ?ディレクトリ内のファイルをタールしてアーカイブを別のディレクトリに置く

#!/bin/bash 

#Author 
#Josh 
++++++++++++++++++++++++++ 
echo "Please enter the name of a folder to archive" 
++++++++++++++++++++++++++ 
echo "Please enter a foldername to store archives in" 
++++++++++++++++++++++++++ 
touch fname 
+++++++++++++++++++++++++ 
tar fname2.tar 
+0

これはCodeReview.SEではありません。 –

+1

重複している可能性があります[アーカイブするフォルダの名前を入力するように求めるメッセージを表示するにはどうすればいいでしょうか?[http://stackoverflow.com/questions/9780649/どのように私がプロンプトを表示するかは、フォルダの名前とアーカイブの名前を入力してからプロンプトを表示してください) –

答えて

2
dir_to_be_tarred= 
while [ ! -d "$dir_to_be_tarred" ]; do  
    echo -n "Enter path to directory to be archived: " # -n makes "echo" not output an ending NEWLINE 
    read dir_to_be_tarred 
    if [ ! -d "$dir_to_be_tarred" ]; then # make sure the directory exists 
     echo "Directory \"$dir_to_be_tarred\" does not exist"  # use quotes around the directory name in case user enter an empty line 
    fi 
done 

storage_dir= 
while [ ! -d "$storage_dir" ]; do 
    echo -n "Enter path to directory where to store the archive: " 
    read storage_dir 
    if [ ! -d "$storage_dir" ]; then 
     echo "Directory \"$storage_dir\" does not exist" 
    fi 
done 

tarfile="$storage_dir"/`date '+%Y%m%d_%H%M%S'`.tar.gz  # the tar archive is named "YYYYMMDD_HHMMSS.tar.gz" 
tar cfz "$tarfile" "$dir_to_be_tarred" 
echo 'Your archive is in: 
'`ls -l "$tarfile"` 
関連する問題