From 63167ca990dabc6405cb41d146dd60c292c6ad73 Mon Sep 17 00:00:00 2001 From: koalaman Date: Mon, 17 Apr 2017 21:40:06 -0700 Subject: [PATCH] Updated SC2164 (markdown) --- SC2164.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/SC2164.md b/SC2164.md index c508ccd..830c566 100644 --- a/SC2164.md +++ b/SC2164.md @@ -31,7 +31,11 @@ func(){ If/when it does, the script will keep going and do all its operations in the wrong directory. This can be messy, especially if the operations involve creating or deleting a lot of files. -You should therefore always check the condition of `cd`, either with `|| exit` as suggested, or things like `if cd somewhere; then ...; fi`. +To avoid this, make sure you handle the cases when `cd` fails. Ways to do this include + +* `cd foo || exit` as suggested to just abort immediately +* `if cd foo; then echo "Ok"; else echo "Fail"; fi` for custom handling +* `<(cd foo && cmd)` as an alternative to `<(cd foo || exit; cmd)` in `<(..)`, `$(..)` or `( )` ### Exceptions: