| Line | |
|---|
| 1 | # aref.bash --- pseudo-array manipulating routines
|
|---|
| 2 | # Author: Noah Friedman <[email protected]>
|
|---|
| 3 | # Created 1992-07-01
|
|---|
| 4 | # Last modified: 1993-02-03
|
|---|
| 5 | # Public domain
|
|---|
| 6 |
|
|---|
| 7 | # Conversion to bash v2 syntax done by Chet Ramey
|
|---|
| 8 |
|
|---|
| 9 | # Commentary:
|
|---|
| 10 | # Code:
|
|---|
| 11 |
|
|---|
| 12 | #:docstring aref:
|
|---|
| 13 | # Usage: aref NAME INDEX
|
|---|
| 14 | #
|
|---|
| 15 | # In array NAME, access element INDEX (0-origin)
|
|---|
| 16 | #:end docstring:
|
|---|
| 17 |
|
|---|
| 18 | ###;;;autoload
|
|---|
| 19 | function aref ()
|
|---|
| 20 | {
|
|---|
| 21 | local name="$1"
|
|---|
| 22 | local index="$2"
|
|---|
| 23 |
|
|---|
| 24 | set -- ${!name}
|
|---|
| 25 | [ $index -ge 1 ] && shift $index
|
|---|
| 26 | echo $1
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | #:docstring string_aref:
|
|---|
| 30 | # Usage: aref STRING INDEX
|
|---|
| 31 | #
|
|---|
| 32 | # Echo the INDEXth character in STRING (0-origin) on stdout.
|
|---|
| 33 | #:end docstring:
|
|---|
| 34 |
|
|---|
| 35 | ###;;;autoload
|
|---|
| 36 | function string_aref ()
|
|---|
| 37 | {
|
|---|
| 38 | local stuff=${1:$2}
|
|---|
| 39 | echo ${stuff:0:1}
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | provide aref
|
|---|
| 43 |
|
|---|
| 44 | # aref.bash ends here
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.