I try to simply concat the arguments if they are not the same..... what is wrong with this simple code for concat???

#!/bin/sh
result=$1

shift
while [ "$#" -ne "0" ]
do

  next=$1

  if [ $result = $next ]
  then
        :
  else

     $result="$result $next"
  fi
shift
done

echo "$result"

if i run it :

$ ./foo a b c
./foo: a=a b: not found
./foo: a=a c: not found
a

why a=a b: not found??? where this came from???

> $result="$result $next"
Remove the first $ perhaps?
Like your other assignment earlier on.

The above from Salem's post needs to be done to fix your issue.. but you may also want to fix your if statement.

if [ "$result" = "$next" ]

The data in these variables are strings and need to be compared as such.

It probably isn't necessary, but you may want to say:

if [ "${result}" = "${next}" ]
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.