Shell scripting. Argh.

Shell scripting. Argh.

Post by Frank v Waver » Mon, 26 Jul 1999 04:00:00



I have a bunch of files in /home/fvw/files, about half of these files is
already on cd-rom, the rest isn't. All files are in subdirectories, wich
themselves don't have subdirs.

I want to delete all the files that are already on the CD, so I tried:

for i in /mnt/cdrom/*/*; do rm /home/fvw/files/$i ; done

But rm give problems because of the spaces in filenames.

So I tried:

for i in /mnt/cdrom/*/*; do rm \"/home/fvw/files/$i\" ; done

Which doesn't work either, because rm thinks the quotes are part of the filename.

Anybody know how to get this working?
--

                        Frank v Waveren

                        ICQ# 10074100

 
 
 

Shell scripting. Argh.

Post by Frank Sweetse » Mon, 26 Jul 1999 04:00:00



Quote:> I have a bunch of files in /home/fvw/files, about half of these files is
> already on cd-rom, the rest isn't. All files are in subdirectories, wich
> themselves don't have subdirs.

> I want to delete all the files that are already on the CD, so I tried:

> for i in /mnt/cdrom/*/*; do rm /home/fvw/files/$i ; done

try this

cd /mnt/cdrom/
find . -type f -exec rm -f "/home/vfw/files/{}" \; -print

note that you might have to escape the "s on the actual command line.

--
Frank Sweetser rasmusin at wpi.edu fsweetser at blee.net  | PGP key available
paramount.ind.wpi.edu RedHat 5.2 kernel 2.2.5        i586 | at public servers
I was trying not to mention backtracking.  Which, of course, means that
yours is "righter" than mine, in a theoretical sense.


 
 
 

Shell scripting. Argh.

Post by Ian Smit » Wed, 28 Jul 1999 04:00:00



> I have a bunch of files in /home/fvw/files, about half of these files is
> already on cd-rom, the rest isn't. All files are in subdirectories, wich
> themselves don't have subdirs.

> I want to delete all the files that are already on the CD, so I tried:

> for i in /mnt/cdrom/*/*; do rm /home/fvw/files/$i ; done

> But rm give problems because of the spaces in filenames.

> So I tried:

> for i in /mnt/cdrom/*/*; do rm \"/home/fvw/files/$i\" ; done

1. it you type
set -x
the shell will tell you what it is _really_ doing!

2. each $i is /mnt/cdrom/diri/filei so /home/fvw/files/$i is actually
/home/fvw/files/mnt/cdrom/diri/filei if you see what I mean.

I think what you want is something like:
cd /mnt/cdrom; for i in */*; do rm /home/fvw/files/$i ; done

--
----------------------------------------------------------------------------
Ian Smith
----------------------------------------------------------------------------

 
 
 

Shell scripting. Argh.

Post by Frank v Waver » Wed, 28 Jul 1999 04:00:00




Quote:> 1. it you type
> set -x
> the shell will tell you what it is _really_ doing!

Ah, cute. Parameters to set... That's more reading of 'man bash' for me :-)

Quote:> 2. each $i is /mnt/cdrom/diri/filei so /home/fvw/files/$i is actually
> /home/fvw/files/mnt/cdrom/diri/filei if you see what I mean.

You're right. I tried to make it into a one-liner for this post, but I fscked
up. DOH.

Quote:> I think what you want is something like:
> cd /mnt/cdrom; for i in */*; do rm /home/fvw/files/$i ; done

I've solved it by now (this was what I started with). The problem was
the fact that there where spaces in the filenames. I tried:
cd /mnt/cdrom; for i in */*; do rm \"/home/fvw/files/$i\" ; done
which didn't work, and I didn't know that env. variables in double quotes
(not in single quotes) where still expanded.

The final line was:
cd /mnt/cdrom; for i in */*; do rm "/home/fvw/files/$i" ; done

Thanks for your help.

--

                        Frank v Waveren

                        ICQ# 10074100

 
 
 

1. handling SIGINT in shell scripts when executing another shell script.

I have a simple shell script foo1.sh that invokes another shell script
foo2.sh, something like below:

#!/bin/sh
SIGINT_handler()
{
  echo "## [$DATE_TIME]  User interrupt ignored,"
  continue
trap SIGINT_handler 2

...
./foo2.sh
...

----------
while executing foo1.sh, if the script receives SIGINT, how do I ignore
the SIGINT in foo2.sh ? somehow foo2.sh does not finish to completion
and is killed after receiving SIGINT. but foo1.sh is still executing.
Is there any way to trap this signal in the child script. ? Please
share your thots and inputs on this topic.
Regards,
Vikram Shekhar

2. DCOPserver not running?

3. Q: How can I have a shell script call another shell script...

4. TOC overflow under AIX 4.1 ???

5. Shell script invoking other shell scripts

6. Yamaha SW60XG

7. Convert Bash shell script to Korn shell script

8. x86 vold doesn't find cd-rom

9. Shell Script Help (C-Shell Script)

10. How to pass a variable from a shell script to another shell script...

11. Shell script acting as interactive shell - $0 not script name??

12. shell script within shell script (general question)

13. Root can't execute shell! Argh