Running a diff on all pairs of arguments

I would like to create a loop and an inner loop to do a diff command on each pair of files passed as arguments. For example, if four files were on the command line, a diff would run on 1-2, 1-3, 1-4, 2-3, 2-4, & 3-4. Thus far I know the $# will give the count of the arguments and argv (instead of shift) would be used to refer to each argument, but I don't know how to define or modify variables which would be used as subscripts.

TIA

What operating system and shell are you using?

Most of us avoid csh when writing scripts, but your reference to argv doesn't sound like you are using a shell based on Bourne shell syntax.

Use two nested for loops, the outer running var_i from 1 to $#-1, the inner running var_j from var_i+1 to $#. You then need eval to run the diff command inside the loops:

eval diff \$$var_i \$$var_j

It's SCO Unix and I believe it uses the Bourne Shell.

If it doesn't have a Bourne shell it's not UNIX.

I don't think you need eval for this:

FIRST="$1"
shift

IFS="^" # Needs to be some char not present in your input
REST="$*"

while [ ! -z "$REST" ]
do
        while [ "$#" -ne - 0 ]
        do
                echo diff "$FIRST" "$1"
                shift
        done

        set -- $REST
        FIRST="$1"
        shift
        REST="$*"
done