| 1 | #! /bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | # CopyArray.sh |
| 3 | # |
| 4 | # This script written by Michael Zick. |
| 5 | # Used here with permission. |
| 6 | |
| 7 | # How-To "Pass by Name & Return by Name" |
| 8 | #+ or "Building your own assignment statement". |
| 9 | |
| 10 | |
| 11 | CpArray_Macscip-shell shell abs-guide 10-4 CpArray_Mac().() { |
| 12 | |
| 13 | # Assignment Command Statement Builder |
| 14 | |
| 15 | echoscip-shell system . . echo. -n 'eval ' |
| 16 | echoscip-shell system . . echo. -n "$2" # Destination name |
| 17 | echoscip-shell system . . echo. -n '=( ${' |
| 18 | echoscip-shell system . . echo. -n "$1" # Source name |
| 19 | echoscip-shell system . . echo. -n '[@]} )' |
| 20 | |
| 21 | # That could all be a single command. |
| 22 | # Matter of style only. |
| 23 | } |
| 24 | |
| 25 | declare -f CopyArray # Function "Pointer" |
| 26 | CopyArray=CpArray_Mac # Statement Builder |
| 27 | |
| 28 | Hypescip-shell shell abs-guide 10-4 Hype().() |
| 29 | { |
| 30 | |
| 31 | # Hype the array named $1. |
| 32 | # (Splice it together with array containing "Really Rocks".) |
| 33 | # Return in array named $2. |
| 34 | |
| 35 | local -a TMP |
| 36 | local -a hype=( Really Rocks ) |
| 37 | |
| 38 | $($CopyArray $1 TMP) |
| 39 | TMP=( ${TMP[@]} ${hype[@]} ) |
| 40 | $($CopyArray TMP $2) |
| 41 | } |
| 42 | |
| 43 | declare -a before=( Advanced Bash Scripting ) |
| 44 | declare -a after |
| 45 | |
| 46 | echoscip-shell system . . echo. "Array Before = ${before[@]}" |
| 47 | |
| 48 | Hypescip-shell shell abs-guide 10-4 Hype(). before after |
| 49 | |
| 50 | echoscip-shell system . . echo. "Array After = ${after[@]}" |
| 51 | |
| 52 | # Too much hype? |
| 53 | |
| 54 | echoscip-shell system . . echo. "What ${after[@]:3:2}?" |
| 55 | |
| 56 | declare -a modest=( ${after[@]:2:1} ${after[@]:3:2} ) |
| 57 | # ---- substring extraction ---- |
| 58 | |
| 59 | echoscip-shell system . . echo. "Array Modest = ${modest[@]}" |
| 60 | |
| 61 | # What happened to 'before' ? |
| 62 | |
| 63 | echoscip-shell system . . echo. "Array Before = ${before[@]}" |
| 64 | |
| 65 | exit 0 |