APPENDIX ATest Switches

One of the fundamental elements of programming is the ability to make comparisons: you test for certain conditions to be able to make decisions. You can use the test command to evaluate many items, such as variables, strings, and numbers. I keep the information in this appendix close at hand since I haven't memorized all of the parameters. I often use these switches for checking files and strings, and this is a simple quick reference for easy lookup. Note that in Table A-1 the "test" column refers to the system command test such as /usr/bin/test. The "bash" and "ksh" columns refer to the built-in test command for those shells.

Table A-1. Test Switches

Switch test bash ksh Definition
-a FILE FILE simply ...

Get Expert Shell Scripting now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.