X-Spam-Check-By: sourceware.org Message-ID: <026001c73aaa$5b8eb940$3001a8c0@Asymmetric> From: "Enrique Perez-Terron" To: "Troy" , References: <8423703 DOT post AT talk DOT nabble DOT com> Subject: Re: Space in Dir Name with shell script and tar Date: Thu, 18 Jan 2007 03:42:54 +0100 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook Express 6.00.2900.3028 X-DCC-nextmail-Metrics: mail42.nsc.no 10042; Body=0 Fuz1=0 Fuz2=0 X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com From: "Troy" To: Sent: Thursday, January 18, 2007 2:50 AM Subject: Space in Dir Name with shell script and tar > > I am trying to make a shell script to do automatic bckups with tar. > > My problem is that tar stumbles on the spaces in the dir names if they are > in a variable. > > Probiably best shown by example > > The dir I want to back up is > g:/Mark I+/Experimental Data/ > > I if do this in the script > tar -czvpf $NAME_OF_BACKUP.tgz /cygdrive/g/Mark' 'I+/Experimental' 'Data/* Try this: tar -czvpf $NAME_OF_BACKUP.tgz "/cygdrive/g/Mark I+/Experimental Data" That is, enclose the name of the directory in double quotation marks, and drop the trailing /* > it works fine but if I do this > > DIRECTORY_TO_BACKUP="/cygdrive/g/Mark' 'I+/Experimental' 'Data" Problem: You are enclosing the apostrophes in the double quotation marks. That means the apostrophes become part of the value of the variable DIRECTORY_TO_BACKUP > tar -czvpf $NAME_OF_BACKUP.tgz $DIRECTORY_TO_BACKUP/* Problem: Bash will replace the variable name with the variable's value, but it will not interpret the apostrophes specially. Interpretation of apostrophes occur at an earlier stage. Next, bash will perform word splitting on the variable's value. This means that the spaces contained in the variable's value will be treated specially, as word splitting points. Try this DIRECTORY_TO_BACKUP="/cygdrive/g/Mark I+/Experimental Data" tar -czvpf $NAME_OF_BACKUP.tgz "$DIRECTORY_TO_BACKUP" i.e., enclose the variable's assigned value in double quotation marks (or apostrophes, if you prefer, but for your convenience, use a single pair around all of the value. Next, enclose the variable substitution in double quotation marks. This time it must be double quotes, not apostrophes, since apostrophes prevent variable substitution. You can tack /* at the end if you want, like this "$DIR"/* but if you want to back up everything in the directory it is better to leave out /*. With /*, files and directories whose names begin with a dot (like .bashrc) are *not* included in the backup. (This applies to files at the top level. A file named "$DIR"/some-subdir/.bashrc is backed up with or without /*.) > > I get > tar: Removing leading `/' from member names This is normal. You are specifying absoluth paths, and then, upon restore, you would be forced to restore to exactly the same path. When tar removes the leading / it becomes possible to restore the data to a different directory, eg to /restored/cygdrive/c/... Here you see another point. It is better to do cd "$DIR" tar cvfpz bakupname.tgz . with a single dot as the backup directory. Then, upon restore, you do not need to have a prefix of directories cygdrive/c/... > tar: /cygdrive/g/Mark': Cannot stat: No such file or directory > tar: 'I+/Experimental': Cannot stat: No such file or directory > tar: 'Data/*: Cannot stat: No such file or directory > tar: Error exit delayed from previous errors > > What am I doing wrong? > -- > View this message in context: > http://www.nabble.com/Space-in-Dir-Name-with-shell-script-and-tar-tf3031755.html#a8423703 > Sent from the Cygwin Users mailing list archive at Nabble.com. > > > -- > Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple > Problem reports: http://cygwin.com/problems.html > Documentation: http://cygwin.com/docs.html > FAQ: http://cygwin.com/faq/ > > > -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/