From 3f25e8f0a0271992fead048c51923bde16eb139a Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Wed, 10 Mar 2021 20:24:11 +0100 Subject: [PATCH] test, [: add page, improve examples (#5205) --- pages/common/[.md | 25 +++++++++++++++++++++++++ pages/common/test.md | 21 +++++++++++---------- 2 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 pages/common/[.md diff --git a/pages/common/[.md b/pages/common/[.md new file mode 100644 index 0000000000..e109dc7e37 --- /dev/null +++ b/pages/common/[.md @@ -0,0 +1,25 @@ +# [ + +> Evaluate condition. +> Returns 0 if the condition evaluates to true, 1 if it evaluates to false. +> More information: . + +- Test if a given variable is equal to a given string: + +`[ "{{$MY_VAR}}" == "{{/bin/zsh}}" ]` + +- Test if a given variable is empty: + +`[ -z "{{$GIT_BRANCH}}" ]` + +- Test if a file exists: + +`[ -f "{{path/to/file_or_directory}}" ]` + +- Test if a directory does not exist: + +`[ ! -d "{{path/to/directory}}" ]` + +- If-else statement: + +`[ {{condition}} ] && {{echo "true"}} || {{echo "false"}}` diff --git a/pages/common/test.md b/pages/common/test.md index ade6a44e79..a0570d98b4 100644 --- a/pages/common/test.md +++ b/pages/common/test.md @@ -1,24 +1,25 @@ # test > Evaluate condition. -> If it is true, returns 0 exit status, otherwise returns 1. +> Returns 0 if the condition evaluates to true, 1 if it evaluates to false. +> More information: . -- Test if given variable is equal to given string: +- Test if a given variable is equal to a given string: -`test $MY_VAR == '/bin/zsh'` +`test "{{$MY_VAR}}" == "{{/bin/zsh}}"` -- Test if given variable is empty: +- Test if a given variable is empty: -`test -z $GIT_BRANCH` +`test -z "{{$GIT_BRANCH}}"` -- Test if file exists: +- Test if a file exists: -`test -e {{filename}}` +`test -f "{{path/to/file_or_directory}}"` -- Test if directory not exists: +- Test if a directory does not exist: -`test ! -d {{path/to/directory}}` +`test ! -d "{{path/to/directory}}"` - If-else statement: -`test {{condition}} && echo "true" || echo "false"` +`test {{condition}} && {{echo "true"}} || {{echo "false"}}`