Previous topic |
Next topic |
Contents |
Contact z/OS |
Library |
PDF
Using test to test conditions z/OS UNIX System Services User's Guide SA23-2279-00 |
|||||||||||||||||||||||||||||||||||||||||||
Before discussing the various control structures, it is useful to talk about ways to test for various conditions. The test command tests to see if something is true. Here are some ways it can be used:
Any of these tests will also work if you put square brackets ([ ]) around the condition instead of using the test command. For example, test 1 -eq 1 is the equivalent of [ 1 -eq 1 ]. The double square bracket [[test_expr]] syntax is also supported. The double square bracket ([[ ]]) also supports additional tests over the test command, and there are some subtle differences between the tests (for example, string equal vs. pattern matching). The result of test is either true or false. test returns a status of 0 if the test turns out to be true and a status of 1 if the test turns out to be false. You can use –n to check if a variable has been
defined. For example:
is true if HOME exists, and false if you have not created a HOME variable.You can use ! to indicate logical negation;
returns false if expression is true, and returns
true if expression is false. For example:
is true if pathname is not a directory, and false
otherwise. |
Copyright IBM Corporation 1990, 2014
|