Ok, to get you started in Bash.

I don't know enough Bash to do arrays or lists, so lets just concentrate 
on argument lists to a function or a script.

cat listtocsv.sh

#!/bin/bash
delim=""
for tok in $*
do
        str="$str${delim}$tok"
        delim=", "
done
echo $str

./listtocsh.sh 1 2 3 4
1, 2, 3, 4

The trick is to eliminate the trailing ", " from the last element of the 
list:
1, 2, 3, 4,

Since Bash doesn't have true functions (that return arbitrary values,) 
the recursive version of this isn't shorter. Can anyone see any 
improvements?

Up next: The Ruby one.

Ed


-- 
Ed Howland
WDT Solutions, LLC.
[EMAIL PROTECTED]
(314) 962-0766

 
_______________________________________________
CWE-LUG mailing list
[email protected]
http://www.cwelug.org/
http://www.cwelug.org/archives/
http://www.cwelug.org/mailinglist/

Reply via email to