Debian Codegraph @

readpipe.sh

raw symbols SCIP
1 #!/bin/sh
2 # readpipe.sh
3 # This example contributed by Bjon Eriksson.
4
5 ### shopt -s lastpipe
6
7 last="(null)"
8 cat $0 |
9 while read line
10 do
11 echo "{$line}"
12 last=$line
13 done
14
15 echo
16 echo "++++++++++++++++++++++"
17 printf "\nAll done, last: $last\n" # The output of this line
18 #+ changes if you uncomment line 5.
19 # (Bash, version -ge 4.2 required.)
20
21 exit 0 # End of code.
22 # (Partial) output of script follows.
23 # The 'echo' supplies extra brackets.
24
25 #############################################
26
27 ./readpipe.sh
28
29 {#!/bin/sh}
30 {last="(null)"}
31 {cat $0 |}
32 {while read line}
33 {do}
34 {echo "{$line}"}
35 {last=$line}
36 {done}
37 {printf "nAll done, last: $lastn"}
38
39
40 All done, last: (null)
41
42 The variable (last) is set within the loop/subshell
43 but its value does not persist outside the loop.