In the course of my job as a computer-fixer I am often asked to back up files from PCs on which Windows has crashed.

In order to ensure that I get every file on the system (both c:\dave and "c:\Documents and Settings\Dave\Local Settings\Application Data \obscure\path\to\important\set\of\mailboxes") and that I don't have to deal with files on the drive that Windows considers to be hidden or system I boot the machine to Linux (usually with a live CD) and take reassurance as the output `cp -rvf * /mnt/portable_hard-drive/ `scrolls down the screen.

This does, however, result in a number of files & directories which are very obviously not needed by the customer on his backup disk, so in order to remove these I mount the disk on another machine & run a series of commands to remove these. I start with `find /path/to/ portable-drive -iname "temporary internet files"`, proceed to `find / path/to/portable-drive -iname "temporary internet files" -exec rm -rf \{} \;` and then make a number of other searches for stuff with different names.

I would like to automate the above process by writing a bash script which will take all the possible find terms and amalgamate them; it should allow some flexibility, interaction and for me to edit the terms easily. Although I'm usually quite decent at writing Bash scripts, I'm stuck at the first hurdle:


        $ cat foo.sh
        
        #!/bin/bash
        UNNEEDED_FILES="pagefile.sys temp 'Temporary Internet Files'"
        for file in "$UNNEEDED_FILES"
        do
          echo I\'ll do stuff to look for "$file"
        done
        
        $ ./foo.sh
        I'll do stuff to look for pagefile.sys temp 'Temporary Internet Files'
        
        $ cat bar.sh
        
        #!/bin/bash
        UNNEEDED_FILES="pagefile.sys temp 'Temporary Internet Files'"
        for file in $UNNEEDED_FILES
        do
          echo I\'ll do stuff to look for "$file"
        done
        
        $ ./bar.sh
        I'll do stuff to look for pagefile.sys
        I'll do stuff to look for temp
        I'll do stuff to look for 'Temporary
        I'll do stuff to look for Internet
        I'll do stuff to look for Files'


I'm afraid quoting really is my Achilles' proverbial in Bash but I've had quite a furtle with this & can't seem to get it to do what I want. All the variables, such as the definition of $UNNEEDED_FILES should remain within the script itself and the output should be:

        $ ./windowcleaner.sh
        I'll do stuff to look for pagefile.sys
        I'll do stuff to look for temp
        I'll do stuff to look for 'Temporary Internet Files'

TIA for any assistance or advice,

Stroller.

--
gentoo-user@gentoo.org mailing list

Reply via email to