source: vendor/bash/3.1-p17/examples/scripts.noah/aref.bash

Last change on this file was 3228, checked in by bird, 18 years ago

bash 3.1

File size: 758 bytes
Line 
1# aref.bash --- pseudo-array manipulating routines
2# Author: Noah Friedman <friedman@prep.ai.mit.edu>
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
19function 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
36function string_aref ()
37{
38 local stuff=${1:$2}
39 echo ${stuff:0:1}
40}
41
42provide aref
43
44# aref.bash ends here
Note: See TracBrowser for help on using the repository browser.