Question: This is Unix and Scripting tools. The given below tells us to write a script called 'listdupes' to compare file(s) with other files to list

This is Unix and Scripting tools. The given below tells us to write a script called 'listdupes' to compare file(s) with other files to list duplicates.

### NAME

`listdupes` - Compares file(s) with other files to list duplicates.

### DESCRIPTION

* When more than one argument is provided (1st form):

Compares the first argument to all of the other arguments.

* When exactly one argument is provided (2nd form):

Compares the given argument to all of the other files in the current directory.

* When no arguments are provided (3rd form):

Compares all files in the current directory to all other files in the current directory.

### EXIT STATUS

| status | meaning |

| --- | --- |

| 0 | if no duplicates were found |

| 1 | if a duplicate was found |

| 2 | if any of the given arguments are not files |

### NOTES

1. a file is never compared to itself (decided by having an identical name)

2. a file is only displayed if it has duplicates

3. duplicates are displayed as:

```

the given source file on a line

each of its duplicates, one per line

a blank line

```

4. when no arguments are given, all combinations of duplicates will be displayed (see last example)

### IMPLEMENTATION NOTES

1. check the arguments for non-files first.

2. create a function named: `dupesOfFirst`

* accepts a list of filenames as arguments

* compares the first argument against all of the others (use the shift command)

* all comparison and display logic should be in here

3. main body of script

* detects the number of arguments

* calls `dupesOfFirst` with the appropriate arguments

### EXAMPLES

Example 1 :

```

echo '1' > tmp1; echo '2' > tmp2; listdupes tmp1 tmp2 ; echo $?

0

```

Example 2 :

```

touch tmp{1..2}; mkdir tmpdir ; listdupes tmp* ; echo $? ; rm -rf tmpdir

not a file: 'tmpdir'

2

```

Example 3 :

```

echo 0 > tmp01 ; cp tmp01 tmp02; cp tmp02 tmp03 ; echo 1 > tmp11; cp tmp11 tmp12; echo 2 > tmp21 ; listdupes tmp01 ; echo $?

tmp01

tmp02

tmp03

1

```

Example 4 :

```

$ echo 0 > tmp01 ; cp tmp01 tmp02; cp tmp02 tmp03 ; echo 1 > tmp11; cp tmp11 tmp12; echo 2 > tmp21 ; listdupes ; echo $?

tmp01

tmp02

tmp03

tmp02

tmp01

tmp03

tmp03

tmp01

tmp02

tmp11

tmp12

tmp12

tmp11

1

```

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!