1 |
On Thu, 14 Apr 2005 16:42:22 -0500 Caleb Tennis <caleb@g.o> |
2 |
wrote: |
3 |
| use blah && ( emake foo || die ) |
4 |
|
5 |
Here's what The Doc will have to say about this: |
6 |
|
7 |
``die`` and Subshells |
8 |
--------------------- |
9 |
|
10 |
.. Warning:: ``die`` **will not work in a subshell**. |
11 |
|
12 |
The following code will not work as expected, since the ``die`` is |
13 |
inside a subshell: :: |
14 |
|
15 |
[[ -f foorc ]] && ( update_foorc || die "couldn't update foorc" ) |
16 |
|
17 |
The correct way to rewrite this is to use an ``if`` block: :: |
18 |
|
19 |
if [[ -f foorc ]] ; then |
20 |
update_foorc || die "couldn't update foorc" |
21 |
fi |
22 |
|
23 |
When using pipes, a subshell is introduced, so the following is unsafe: |
24 |
:: |
25 |
|
26 |
cat list | while read file ; do epatch ${file} ; done |
27 |
|
28 |
Using input redirection (see `Abuse of cat`_) avoids this problem: :: |
29 |
|
30 |
while read file ; do epatch ${file} ; done < list |
31 |
|
32 |
|
33 |
-- |
34 |
Ciaran McCreesh : Gentoo Developer (Vim, Fluxbox, shell tools) |
35 |
Mail : ciaranm at gentoo.org |
36 |
Web : http://dev.gentoo.org/~ciaranm |