Gentoo Archives: gentoo-user

From: Stroller <stroller@××××××××××××××××××.uk>
To: gentoo-user@l.g.o
Subject: [gentoo-user] OT: bash scripting help requested. Quoting?
Date: Wed, 22 Mar 2006 07:14:44
Message-Id: 2EE51ED4-3ABA-4027-AF52-E8DC44631CF4@stellar.eclipse.co.uk
1 In the course of my job as a computer-fixer I am often asked to back
2 up files from PCs on which Windows has crashed.
3
4 In order to ensure that I get every file on the system (both c:\dave
5 and "c:\Documents and Settings\Dave\Local Settings\Application Data
6 \obscure\path\to\important\set\of\mailboxes") and that I don't have
7 to deal with files on the drive that Windows considers to be hidden
8 or system I boot the machine to Linux (usually with a live CD) and
9 take reassurance as the output `cp -rvf * /mnt/portable_hard-drive/
10 `scrolls down the screen.
11
12 This does, however, result in a number of files & directories which
13 are very obviously not needed by the customer on his backup disk, so
14 in order to remove these I mount the disk on another machine & run a
15 series of commands to remove these. I start with `find /path/to/
16 portable-drive -iname "temporary internet files"`, proceed to `find /
17 path/to/portable-drive -iname "temporary internet files" -exec rm -rf
18 \{} \;` and then make a number of other searches for stuff with
19 different names.
20
21 I would like to automate the above process by writing a bash script
22 which will take all the possible find terms and amalgamate them; it
23 should allow some flexibility, interaction and for me to edit the
24 terms easily. Although I'm usually quite decent at writing Bash
25 scripts, I'm stuck at the first hurdle:
26
27
28 $ cat foo.sh
29
30 #!/bin/bash
31 UNNEEDED_FILES="pagefile.sys temp 'Temporary Internet Files'"
32 for file in "$UNNEEDED_FILES"
33 do
34 echo I\'ll do stuff to look for "$file"
35 done
36
37 $ ./foo.sh
38 I'll do stuff to look for pagefile.sys temp 'Temporary Internet Files'
39
40 $ cat bar.sh
41
42 #!/bin/bash
43 UNNEEDED_FILES="pagefile.sys temp 'Temporary Internet Files'"
44 for file in $UNNEEDED_FILES
45 do
46 echo I\'ll do stuff to look for "$file"
47 done
48
49 $ ./bar.sh
50 I'll do stuff to look for pagefile.sys
51 I'll do stuff to look for temp
52 I'll do stuff to look for 'Temporary
53 I'll do stuff to look for Internet
54 I'll do stuff to look for Files'
55
56
57 I'm afraid quoting really is my Achilles' proverbial in Bash but I've
58 had quite a furtle with this & can't seem to get it to do what I
59 want. All the variables, such as the definition of $UNNEEDED_FILES
60 should remain within the script itself and the output should be:
61
62 $ ./windowcleaner.sh
63 I'll do stuff to look for pagefile.sys
64 I'll do stuff to look for temp
65 I'll do stuff to look for 'Temporary Internet Files'
66
67 TIA for any assistance or advice,
68
69 Stroller.
70
71 --
72 gentoo-user@g.o mailing list

Replies

Subject Author
Re: [gentoo-user] OT: bash scripting help requested. Quoting? Iain Buchanan <iaindb@××××××××××××.au>
Re: [gentoo-user] OT: bash scripting help requested. Quoting? Neil Bothwick <neil@××××××××××.uk>