File: assignments.org

package info (click to toggle)
gash 0.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 896 kB
  • sloc: lisp: 6,241; makefile: 281; sh: 133
file content (157 lines) | stat: -rw-r--r-- 2,760 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
;;; Gash -- Guile As SHell
;;; Copyright © 2016, 2017, 2018 R.E.W. van Beusekom <rutger.van.beusekom@gmail.com>
;;; Copyright © 2018, 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
;;; Copyright © 2019 Timothy Sample <samplet@ngyro.com>
;;;
;;; This file is part of Gash.
;;;
;;; Gash is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation, either version 3 of the License, or
;;; (at your option) any later version.
;;;
;;; Gash is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with Gash.  If not, see <http://www.gnu.org/licenses/>.

* assignment-backtick
:script:
#+begin_src sh
  obj=ar.o
  objs="$objs `basename $obj`"
  echo "objs:>$objs<"
#+end_src
:stdout:
#+begin_example
  objs:> ar.o<
#+end_example

* assignment-doublequoted-doublequotes
:script:
#+begin_src sh
  aliaspath=alias
  localedir=locale
  defines="-DALIASPATH=\"${aliaspath}\" -DLOCALEDIR=\"${localedir}\""
  echo cc $defines
#+end_src
:stdout:
#+begin_example
  cc -DALIASPATH="alias" -DLOCALEDIR="locale"
#+end_example

* assignment-double-quote
:script:
#+begin_src sh
  srcdir="."
#+end_src

* assignment-echo
:script:
#+begin_src sh
  SHELL=/bin/bash
  echo $SHELL
#+end_src
:stdout:
#+begin_example
  /bin/bash
#+end_example

* assignment-empty
:script:
#+begin_src sh
  a=
  echo a:$a
#+end_src
:stdout:
#+begin_example
  a:
#+end_example

* assignment
:script:
#+begin_src sh
  SHELL=/bin/bash
#+end_src

* assignment-singlequote
:script:
#+begin_src sh
  srcdir='.'
#+end_src

* assignment-variable-word
:script:
#+begin_src sh
  SHELL=gash
  bin=${SHELL}/bin
  echo $bin
#+end_src
:stdout:
#+begin_example
  gash/bin
#+end_example

* assignment-word-variable
:script:
#+begin_src sh
  SHELL=gash
  PATH=bin:${SHELL}
  echo $PATH
#+end_src
:stdout:
#+begin_example
  bin:gash
#+end_example

* Assignments reset exit status
:script:
#+begin_src sh
  set +e
  false
  x=foobar
#+end_src

* Assigning exit status works
:script:
#+begin_src sh
  set +e
  false
  x=$?
  echo $x
#+end_src
:stdout:
#+begin_example
  1
#+end_example

* Assignments use command substitutions for exit status
:script:
#+begin_src sh
  set +e
  x=$(false)
  echo $?
  x=$(true)
  echo $?
#+end_src
:stdout:
#+begin_example
  1
  0
#+end_example

* Assignments update exit status on the fly
:script:
#+begin_src sh
  set +e
  false
  x=$? y=$(true) z=$?
  echo $x $z
#+end_src
:stdout:
#+begin_example
  1 0
#+end_example