Shell scripting-concatenate the argument lists


Question:

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.

Examples:

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

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

prompt>clean_list apple:orange:apple pear orange peach
apple:orange:pear:peach

Solution Preview :

Prepared by a verified Expert
Other Subject: Shell scripting-concatenate the argument lists
Reference No:- TGS01937337

Now Priced at $20 (50% Discount)

Recommended (95%)

Rated (4.7/5)