summaryrefslogtreecommitdiff
path: root/examples/functions/array-to-string
diff options
context:
space:
mode:
authorJari Aalto <jari.aalto@cante.net>2001-04-06 19:14:31 +0000
committerJari Aalto <jari.aalto@cante.net>2009-09-12 16:46:53 +0000
commit28ef6c316f1aff914bb95ac09787a3c83c1815fd (patch)
tree2812fe7ffc9beec4f99856906ddfcafda54cf16a /examples/functions/array-to-string
parentbb70624e964126b7ac4ff085ba163a9c35ffa18f (diff)
downloadbash-28ef6c316f1aff914bb95ac09787a3c83c1815fd.tar.gz
Imported from ../bash-2.05.tar.gz.
Diffstat (limited to 'examples/functions/array-to-string')
-rw-r--r--examples/functions/array-to-string15
1 files changed, 15 insertions, 0 deletions
diff --git a/examples/functions/array-to-string b/examples/functions/array-to-string
new file mode 100644
index 00000000..0d2fbe50
--- /dev/null
+++ b/examples/functions/array-to-string
@@ -0,0 +1,15 @@
+#! /bin/bash
+
+# Format: array_to_string vname_of_array vname_of_string separator
+array_to_string()
+{
+ (( ($# < 2) || ($# > 3) )) && {
+ "$FUNCNAME: usage: $FUNCNAME arrayname stringname [separator]"
+ return 2
+ }
+
+ local array=$1 string=$2
+ ((3==$#)) && [[ $3 = ? ]] && local IFS="${3}${IFS}"
+ eval $string="\"\${$array[*]}\""
+ return 0
+}