1 |
#!/bin/bash |
2 |
|
3 |
# Weird case from bash-help mailing list. |
4 |
# |
5 |
# "Evaluations of backticks in if statements". It doesn't relate to if |
6 |
# statements but to $?, since && and || behave the same way. |
7 |
|
8 |
# POSIX has a special rule for this. In OSH strict-argv is preferred so it |
9 |
# becomes a moot point. I think this is an artifact of the |
10 |
# "stateful"/imperative nature of $? -- it can be "left over" from a prior |
11 |
# command, and sometimes the prior argv is []. OSH has a more "functional" |
12 |
# implementation so it doesn't have this weirdness. |
13 |
|
14 |
#### If empty command |
15 |
if ''; then echo TRUE; else echo FALSE; fi |
16 |
## stdout: FALSE |
17 |
## status: 0 |
18 |
|
19 |
#### If subshell true |
20 |
if `true`; then echo TRUE; else echo FALSE; fi |
21 |
## stdout: TRUE |
22 |
## status: 0 |
23 |
|
24 |
#### If subshell true WITH OUTPUT is different |
25 |
if `sh -c 'echo X; true'`; then echo TRUE; else echo FALSE; fi |
26 |
## stdout: FALSE |
27 |
## status: 0 |
28 |
|
29 |
#### If subshell true WITH ARGUMENT |
30 |
if `true` X; then echo TRUE; else echo FALSE; fi |
31 |
## stdout: FALSE |
32 |
## status: 0 |
33 |
|
34 |
#### If subshell false -- exit code is propagated in a weird way (strict-argv prevents) |
35 |
if `false`; then echo TRUE; else echo FALSE; fi |
36 |
## stdout: FALSE |
37 |
## status: 0 |