|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "is.sh" |
| 4 | +description: "Fancy alternative for old good test command" |
| 5 | +category: bash |
| 6 | +tags: [utility, condition, bash] |
| 7 | +--- |
| 8 | + |
| 9 | +**is.sh** allows you to write conditions which can be read by average human being. |
| 10 | + |
| 11 | + |
| 12 | +## Usage |
| 13 | + |
| 14 | +{% highlight bash %} |
| 15 | +var=123 |
| 16 | + |
| 17 | +if is equal $var 123.0; then |
| 18 | + echo "it just works" |
| 19 | +fi |
| 20 | + |
| 21 | +if is not a substring $var "foobar"; then |
| 22 | + echo "and it's easy to read" |
| 23 | +fi |
| 24 | +{% endhighlight %} |
| 25 | + |
| 26 | + |
| 27 | +### Available conditions |
| 28 | + |
| 29 | +* ``is equal <valueA> <valueB>`` - checks if values are the same or if they are equal numbers |
| 30 | +* ``is matching <value> <regexp>`` - checks if whole value matches to regular expression |
| 31 | +* ``is substring <value> <string>`` - checks if first value is a part of second one |
| 32 | +* ``is empty <value>`` - checks if value is empty |
| 33 | +* ``is number <value>`` - checks if value is a number |
| 34 | +* ``is gt <numberA> <numberB>`` - true if first number is greater than second one |
| 35 | +* ``is lt <numberA> <numberB>`` - true if first number is less than second one |
| 36 | +* ``is ge <numberA> <numberB>`` - true if first number is greater than or equal to second one |
| 37 | +* ``is le <numberA> <numberB>`` - true if first number is less than or equal to second one |
| 38 | +* ``is file <path>`` - checks if it is a file |
| 39 | +* ``is dir <path>`` - checks if it is a directory |
| 40 | +* ``is link <path>`` - checks if it is a symbolic link |
| 41 | +* ``is existent <path>`` - checks if there is a file or directory or anything else with this path |
| 42 | +* ``is readable <path>`` - checks if file is readable |
| 43 | +* ``is writeable <path>`` - checks if file is writeable |
| 44 | +* ``is executable <path>`` - checks if file is executable |
| 45 | +* ``is older <pathA> <pathB>`` - checks if first file is older than second one |
| 46 | +* ``is newer <pathA> <pathB>`` - checks if first file is newer than second one |
| 47 | +* ``is true <value>`` - true if value is equal "true" or "0" |
| 48 | +* ``is false <value>`` - oposite of ``is true <value>`` |
| 49 | + |
| 50 | + |
| 51 | +### Negations |
| 52 | + |
| 53 | +You can negate any condition by putting ``not`` in front of it: |
| 54 | + |
| 55 | +{% highlight bash %} |
| 56 | +$ is a number "abc" && echo "number" |
| 57 | +$ is not a number "abc" && echo "not a number" |
| 58 | +not a number |
| 59 | +{% endhighlight %} |
| 60 | + |
| 61 | + |
| 62 | +## Links |
| 63 | + |
| 64 | +* [Source Code (GitHub)](https://github.com/qzb/is.sh); |
| 65 | +* Author: [Józef Sokołowski](https://github.com/qzb); |
| 66 | + |
0 commit comments