Reputation: 3972
Very simple script but no idea why it sends an exit code of 1...
docker run --rm -it alpine
/ # apk update && apk add curl
...
...
/ # func() { RESPCODE=$(curl -sS -w "%{http_code}" -o /dev/null https://jsonplaceholder.typicode.com/todos/1); EXITCODE=$?; [ $EXITCODE -ne 0 ] && return 2; }
/ # func
/ # echo $?
1
Why does it not exit with zero code?!
Upvotes: 0
Views: 35
Reputation: 141493
curl
suceeds.EXITCODE=0
The exit status of an AND list shall be the exit status of the last command that is executed in the list.
[ $EXITCODE -ne 0 ]
exits with 1
exit statusreturn 2
does not execute[ $EXITCODE -ne 0 ] && return 2
is [ $EXITCODE -ne 0 ]
[ $EXITCODE -ne 0 ]
exited with 1
exit status[ $EXITCODE -ne 0 ] && return 2
is 11
exit status.1
exit statusecho $?
outputs 1
Do not use &&
nor ||
as a condition. Use if
.
Upvotes: 1