Fancy alternative for old good test command.
var=123
if is equal $var 123.0; then
echo "it just works"
fi
if is not a substring $var "foobar"; then
echo "and it's easy to read"
fi
In order to use is.sh you can download it and source it from your script or
.bashrc:
$ wget raw.githubusercontent.com/hagenw/is.sh/latest/is.sh
$ source ./is.sh
is equal $valueA $valueB
- checks if values are the same or if they are equal numbersis matching $regexp $value
- checks if whole value matches to regular expressionis substring $valueA $valueB
- checks if first value is a part of second oneis variable $value
- checks if value is an existing variableis empty $value
- checks if value is emptyis number $value
- checks if value is a numberis gt $numberA $numberB
- true if first number is greater than second oneis lt $numberA $numberB
- true if first number is less than second oneis ge $numberA $numberB
- true if first number is greater than or equal to second oneis le $numberA $numberB
- true if first number is less than or equal to second oneis file $path
- checks if it is a fileis dir $path
- checks if it is a directoryis link $path
- checks if it is a symbolic linkis existent $path
- checks if there is a file or directory or anything else with this pathis readable $path
- checks if file is readableis writeable $path
- checks if file is writeableis executable $path
- checks if file is executableis available $command
- checks if given command is availableis older $pathA $pathB
- checks if first file is older than second oneis newer $pathA $pathB
- checks if first file is newer than second oneis true $value
- true if value is equal "true" or "0"is false $value
- opposite ofis true $value
You can negate any condition by putting not in front of it.
$ is number "abc" && echo "number"
$ is not number "abc" && echo "not a number"
not a number
You can add a, an, and the articles before condition name.
$ is a number 5
$ is not a substring abc defghi
MIT