Write a shell program with input

Hi,

Here is my question:

I want a shell script which I name as 'del', and can be used as del(string).

when run del(string), it will delete several directories at different locations in my system,like:

rm -fr /lustre/fs/scratch/user/$string
rm -fr /home/user/$string
rm -fr /archive/user/$string
.
.
and so on

Thanks!

#! /bin/bash

arr=( "/path/to/file1" "/path/to/file2" )

for file in ${arr[@]}
do
    rm -rf $file
done

Your question leaves too many things to guess for.

1 what does (string) mean?
2. what does string have to do with what the sheel script does - is it just a name?
3. Your example rm statements seem to be random, you could put them in a script named almost anything you want and it could make some sense. Why can we not name the script "foo"? Why does the name need to have any effect on the operation of the script?

this command is so dangerous, if string is not defined correctly (empty), the whole three folders will be deleted directly without any prompt by "rm -rf"

---------- Post updated at 01:51 PM ---------- Previous update was at 01:49 PM ----------

try this

string=abc
for folder in /lustre/fs/scratch/user /home/user /archive/user
do
  find $folder -type d -name "$string" -exec rm -rf {} \;
done

If you want to search this directory in lot of different directories you can try this

find / -type d -name $string

and then the rest of the command as given by rdcwayx. It will search for your string from the root directory. But you need to be very sure that you are typing correct string name as it could be very risky.:slight_smile: