[[, [: add/update pages (#7530)

This commit is contained in:
Emily Grace Seville
2021-12-22 07:28:01 +10:00
committed by GitHub
parent 844a561415
commit 8d8634bb19
2 changed files with 56 additions and 11 deletions

View File

@@ -2,24 +2,32 @@
> Check file types and compare values.
> Returns 0 if the condition evaluates to true, 1 if it evaluates to false.
> More information: <https://www.gnu.org/software/coreutils/test>.
> More information: <https://www.gnu.org/software/bash/manual/bash.html#index-test>.
- Test if a given variable is equal to a given string:
- Test if a given variable is equal/not equal to the specified string:
`[ "{{$VARIABLE}}" == "{{/bin/zsh}}" ]`
`[ "${{variable}}" {{==|!=}} "{{string}}" ]`
- Test if a given variable is empty:
- Test if a given variable is [eq]ual/[n]ot [e]qual/[g]reater [t]han/[l]ess [t]han/[g]reater than or [e]qual/[l]ess than or [e]qual to the specified number:
`[ -z "{{$GIT_BRANCH}}" ]`
`[ "${{variable}}" -{{eq|ne|gt|lt|ge|le}} {{integer}} ]`
- Test if a file exists:
- Test if the specified variable has a [n]on-empty value:
`[ -f "{{path/to/file}}" ]`
`[ -n "${{variable}}" ]`
- Test if a directory does not exist:
- Test if the specified variable has an empty value:
`[ ! -d "{{path/to/directory}}" ]`
`[ -z "${{variable}}" ]`
- If-else statement:
- Test if the specified [f]ile exists:
`[ {{condition}} ] && {{echo "true"}} || {{echo "false"}}`
`[ -f {{path/to/file}} ]`
- Test if the specified [d]irectory exists:
`[ -d {{path/to/directory}} ]`
- Test if the specified file or directory [e]xists:
`[ -e {{path/to/file_or_directory}} ]`

37
pages/common/[[.md Normal file
View File

@@ -0,0 +1,37 @@
# [[
> Check file types and compare values.
> Returns 0 if the condition evaluates to true, 1 if it evaluates to false.
> More information: <https://www.gnu.org/software/bash/manual/bash.html#index-_005b_005b>.
- Test if a given variable is equal/not equal to the specified string:
`[[ ${{variable}} {{==|!=}} "{{string}}" ]]`
- Test if a given string conforms the specified glob/regex:
`[[ ${{variable}} {{==|=~}} {{pattern}} ]]`
- Test if a given variable is [eq]ual/[n]ot [e]qual/[g]reater [t]han/[l]ess [t]han/[g]reater than or [e]qual/[l]ess than or [e]qual to the specified number:
`[[ ${{variable}} -{{eq|ne|gt|lt|ge|le}} {{integer}} ]]`
- Test if the specified variable has a [n]on-empty value:
`[[ -n ${{variable}} ]]`
- Test if the specified variable has an empty value:
`[[ -z ${{variable}} ]]`
- Test if the specified [f]ile exists:
`[[ -f {{path/to/file}} ]]`
- Test if the specified [d]irectory exists:
`[[ -d {{path/to/directory}} ]]`
- Test if the specified file or directory [e]xists:
`[[ -e {{path/to/file_or_directory}} ]]`