~ubuntu-branches/ubuntu/trusty/bash/trusty-security

« back to all changes in this revision

Viewing changes to tests/nameref5.sub

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2014-03-03 22:52:05 UTC
  • mfrom: (1.3.5) (2.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20140303225205-87ltrt5kspeq0g1b
Tags: 4.3-1ubuntu1
* Merge with Debian; remaining changes:
  - skel.bashrc:
    - Run lesspipe.
    - Enable ls aliases.
    - Set options in ll alias to -alF.
    - Define an alert alias.
    - Enabled colored grep aliases.
  - etc.bash.bashrc:
    - Add sudo hint.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# nameref variables as for loop index variables are special
 
2
v1=1
 
3
v2=2
 
4
 
 
5
# simple for loop
 
6
for v in v1 v2
 
7
do
 
8
        typeset -n ref=$v
 
9
        echo $ref
 
10
done
 
11
unset v
 
12
 
 
13
set -- first second third fourth fifth
 
14
 
 
15
# unless you put a ${!v} in the for loop, ksh93 misbehaves
 
16
typeset -n v=v1
 
17
for v in v1 v2; do
 
18
        echo "${!v}: $v"
 
19
done
 
20
unset v
 
21
 
 
22
# example cribbed from ksh93 o'reilly book
 
23
first="I am first"
 
24
second="I am in the middle"
 
25
third="I am last"
 
26
 
 
27
typeset -n ref=first
 
28
for ref in first second third ; do
 
29
        echo "ref -> ${!ref}, value: $ref"
 
30
done
 
31
echo final state: "ref -> ${!ref}, value: $ref"
 
32
 
 
33
readonly one=1
 
34
readonly two=2
 
35
readonly three=3
 
36
 
 
37
typeset -n ref=one
 
38
for ref in one two three; do
 
39
        echo "ref -> ${!ref}, value: $ref"
 
40
done
 
41
echo final state: "ref -> ${!ref}, value: $ref"
 
42
 
 
43
unset ref
 
44
typeset -n ref=one
 
45
readonly ref
 
46
 
 
47
for ref in one two three; do
 
48
        echo "ref -> ${!ref}, value: $ref"
 
49
done
 
50
echo final state: "ref -> ${!ref}, value: $ref"