Explore BrainMass

Shell scripting: concatenate the argument lists

Write a Bash script to concatenate the argument lists and output the resulting list. Final list should not include any argument that is a sub-list of the entire list. The script should not leave any redundant elements in the concatenated list, and it should maintain the order of the elements in the input. Examples below give a better idea about expected script behaviour.

Script should also account for the following situations:

a : at the beginning of the list is the same as a . at the beginning of the "list" (:/bin is the same a .:/bin)
a :: any where in the list is the same as :.: (/bin::/etc is the same as (/bin:.:/etc)
a : at the end of the list is the same a :. ( /bin: is the same as /bin:. )

The input to the script will be one or more space separated lists with elements in individual lists separated by colon, and the output will be a single colon separated list with all redundant elements removed.


prompt> clean_list a a:b a:b:c :x: y:z

prompt>clean_list /bin:/usr/bin:/usr/openwin/bin /usr/bin:/usr/etc:/etc: /usr/bin/X11 .:/bin

prompt>clean_list apple:orange:apple pear orange peach

Solution Preview

Please rename attached to before you run it. Script has been tested for the given ...

Solution Summary

Script given in solution does not use any temporary files, and is reasonably commented. It also defines and uses shell functions for better readability and understandability. Script has been well tested for the given examples and few extra boundary cases.