Wrapping commands in scripts

You've come to this page because you've asked a question similar to the following:

I am using the tail command (from The OS/2 Command Line Utilities). As the documentation says, it defaults, if I don't tell it otherwise, to printing just one line. I want it to print the last hundred lines, without, however, having to specify the /100 option every time that I run it. How do I achieve this ?

One way to add options to every invocation of a command is to wrap it in a command script of the same name. Just create a script named tail.cmd and place it either in the same directory as tail.exe itself or in a directory that is listed earlier in the path than that directory.

If you are using JP Software's 4OS2 or The 32-bit Command Interpreter, both of which can vary the order in which extensions are searched, you must also ensure that your PATHEXT environment variable specifies that the command interpreter appends the .cmd extension before it appends the .exe extension when searching for files. You can always use another extension, such as .btm, for the wrapper script filename if you need to.

Here is a very simple command script that adds /100 to tail that shows the form that such a wrapper command script takes. There are two main points to remember:

One more thing to note:

If you prepend non-option arguments to a command, you may well, depending from what the command is, alter the default behaviour of the command. So be careful, and only do this if it is what you really want. For example: When invoked with no non-option arguments, the tail utility itself reads from its standard input, enabling it to be used in command pipelines. However, a wrapper script that always prepended non-option arguments would result in this behaviour not occuring when one invoked the tail command without arguments. This could cause surprise if one were expecting to be able to use the tail command as part of a command pipeline.

© Copyright 2002-2002 Jonathan de Boyne Pollard. "Moral" rights asserted.
Permission is hereby granted to copy and to distribute this web page in its original, unmodified form as long as its last modification datestamp is preserved.