summaryrefslogtreecommitdiff
path: root/doc/bash-style.cli
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2018-07-21 15:04:15 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2018-07-21 15:04:15 +0200
commit1e70f54ccdcd9b6a1aea1230dadc2539cc42b0f1 (patch)
treecb879a986be8a0ef2d4d17ae70ccb406b2f02296 /doc/bash-style.cli
parente706898811cb4e95ec37a5707227d8e129f29eda (diff)
Update bash style guide
Diffstat (limited to 'doc/bash-style.cli')
-rw-r--r--doc/bash-style.cli33
1 files changed, 32 insertions, 1 deletions
diff --git a/doc/bash-style.cli b/doc/bash-style.cli
index 93cf9e0..f81479b 100644
--- a/doc/bash-style.cli
+++ b/doc/bash-style.cli
@@ -54,7 +54,8 @@ done
\
For \c{if} use \c{[ ]} for basic tests and \c{[[ ]]} only if the previous form
-is not sufficient. Never use \c{test}. Do use \c{elif}.
+is not sufficient. Use \c{test} for filesystem tests (presence of files,
+etc). Do use \c{elif}.
\h1#struct|Structure|
@@ -282,12 +283,42 @@ if ! grep \"foo\" /tmp/bar; then
fi
\
+Note that the \c{if}-condition can be combined with capturing the output, for
+example:
+
+\
+if v=\"$(...)\"; then
+ ...
+fi
+\
+
If you need to ignore the exit status, you can use \c{|| true}, for example:
\
foo || true
\
+
+\h1#bool|Boolean|
+
+For boolean values use empty for false and \c{true} for true. This way you
+can have terse and natural looking conditions, for example:
+
+\
+first=true
+while ...; do
+
+ if [ ! \"$first\" ]; then
+ ...
+ fi
+
+ if [ \"$first\" ]; then
+ first=
+ fi
+
+done
+\
+
\h1#function|Functions|
If a function takes arguments, provide a brief usage after the function