#!/bin/bash

OUTPUT=
CONCAT=

SAVEIFS=$IFS
 IFS=","
 declare -a CHANNEL_ARRAY=($1)
IFS=$SAVEIFS

for CHANNEL in ${CHANNEL_ARRAY[@]}
do
   case "$CHANNEL" in
      master)
           OUTPUT=${OUTPUT}${CONCAT}master,wave,microphone,speaker,cd,linein,linein1,linein2,linein3
           ;;
      wave)
           OUTPUT=${OUTPUT}${CONCAT}master
           ;;
      *)
           OUTPUT=${OUTPUT}${CONCAT}$CHANNEL
           ;;
   esac
   CONCAT=,
done

echo $OUTPUT

