-
-
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.
- Loading branch information
Emily Grace Seville
authored
Dec 21, 2021
1 parent
844a561
commit 8d8634b
Showing
2 changed files
with
56 additions
and
11 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
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,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}} ]]` |