unknown_error_bypass
This commit is contained in:
+26
-1
@@ -35,4 +35,29 @@ count=0
|
||||
```bash
|
||||
count=0
|
||||
count=$((count+1))
|
||||
`
|
||||
```
|
||||
|
||||
## properly grab $?
|
||||
|
||||
> prefer plain `command` rather than `! command`
|
||||
> otherwise you will miss out the exit code
|
||||
|
||||
### wrong if
|
||||
|
||||
```bash
|
||||
if ! command; then
|
||||
local code=$?
|
||||
>&2 echo $code # => 0
|
||||
fi
|
||||
```
|
||||
|
||||
### right if
|
||||
|
||||
```bash
|
||||
if command; then
|
||||
: # useful for preserving $?
|
||||
else
|
||||
local code=$?
|
||||
>&2 echo $code
|
||||
fi
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user