I have shell script where i have set -e in first line and I am checking for binary in path using where kubectl
. If kubectl is not present on system then this command returns non-zero error hence entire script break. I want to silence functionality of set -e
while running where
command. Is there a way I can protect script from exiting or in other words ignore return code of selective command in script?
Asked
Active
Viewed 24 times
0

prashant
- 2,808
- 5
- 26
- 41
-
use `set +e` to do that – P.... May 31 '19 at 18:03
-
I tried that out but on setting it back it doesn't exit on error – prashant May 31 '19 at 18:05
-
1@prashant: Use the logic as mentioned in the other answer. `where kubectl || : `. Even better to avoid the error statement `where kubectl 2>/dev/null || : ` – Inian May 31 '19 at 18:06
-
[Don't use `set -e` - ever.](http://mywiki.wooledge.org/BashFAQ/105) – Dennis Williamson May 31 '19 at 20:33
-
@dennis what is the best solution to it – prashant Jun 01 '19 at 05:01
-
ok got it, I missed the link you mention – prashant Jun 01 '19 at 11:54