-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test, [: add page, improve examples (#5205)
- Loading branch information
Showing
2 changed files
with
36 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# [ | ||
|
||
> Evaluate condition. | ||
> Returns 0 if the condition evaluates to true, 1 if it evaluates to false. | ||
> More information: <https://www.gnu.org/software/coreutils/manual/html_node/test-invocation.html>. | ||
- 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"}}` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: <https://www.gnu.org/software/coreutils/manual/html_node/test-invocation.html>. | ||
- 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"}}` |