Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[[, [: add/update pages #7530

Merged
merged 15 commits into from Dec 21, 2021
22 changes: 11 additions & 11 deletions pages/common/[.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@

> 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#Conditional-Constructs>.
EmilyGraceSeville7cf marked this conversation as resolved.
Show resolved Hide resolved

- Test if a given variable is equal to a given string:
- Test if two strings are equal/not equal:
EmilyGraceSeville7cf marked this conversation as resolved.
Show resolved Hide resolved

`[ "{{$VARIABLE}}" == "{{/bin/zsh}}" ]`
`[ "${{variable}}" {{==|=!}} "{{string}}" ]`
EmilyGraceSeville7cf marked this conversation as resolved.
Show resolved Hide resolved

- Test if a given variable is empty:
- Test if two numbers are [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:

`[ -z "{{$GIT_BRANCH}}" ]`
EmilyGraceSeville7cf marked this conversation as resolved.
Show resolved Hide resolved
`[ "${{variable}}" -{{eq|ne|gt|lt|ge|le}} "{{string}}" ]`

- Test if a file exists:
- Test if a the specified [f]ile exist:

`[ -f "{{path/to/file}}" ]`
`[ -f {{path/to/file}} ]`

- Test if a directory does not exist:
- Test if a the specified [d]irectory exist:

`[ ! -d "{{path/to/directory}}" ]`
`[ -d {{path/to/directory}} ]`

- If-else statement:
- Test if a the specified file or directory [e]xist:

`[ {{condition}} ] && {{echo "true"}} || {{echo "false"}}`
`[ -e {{path/to/file_or_directory}} ]`
29 changes: 29 additions & 0 deletions pages/common/[[.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# [[

> 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#Conditional-Constructs>.
EmilyGraceSeville7cf marked this conversation as resolved.
Show resolved Hide resolved

- Test if two strings are equal/not equal:

`[[ ${{variable}} {{==|=!}} "{{string}}" ]]`
EmilyGraceSeville7cf marked this conversation as resolved.
Show resolved Hide resolved

- Test if a string conforms the specified glob/regex:

`[[ ${{variable}} {{==|=~}} {{pattern}} ]]`

- Test if two numbers are [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:

`[[ ${{variable}} -{{eq|ne|gt|lt|ge|le}} "{{string}}" ]]`

- Test if a the specified [f]ile exist:
EmilyGraceSeville7cf marked this conversation as resolved.
Show resolved Hide resolved

`[[ -f {{path/to/file}} ]]`

- Test if a the specified [d]irectory exist:
EmilyGraceSeville7cf marked this conversation as resolved.
Show resolved Hide resolved

`[[ -d {{path/to/directory}} ]]`

- Test if a the specified file or directory [e]xist:
EmilyGraceSeville7cf marked this conversation as resolved.
Show resolved Hide resolved

`[[ -e {{path/to/file_or_directory}} ]]`