27-03-2012, 03:11 PM
Win32 Shell Scripting Tutorial
batchFiles-2.pdf (Size: 51.69 KB / Downloads: 46)
Introduction to Win32 Shell Scripting
Time is precious. It is non-sense-ical to waste time typing a frequently used sequence of commands at a command prompt, more
especially if they are abnormally long or complex. Scripting is a way by which one can alleviate this necessity by automating these
command sequences in order to make ones life at the shell easier and more productive. Scripting is all about making the computer,
the tool do the work. Hopefully by the end of this tutorial you should have a good idea of the kinds of scripting languages available
for Windows and how to apply them to your problems.
The Environment
The environment is an area of memory associated with the command processor that provides upto 32KB of space for storing variables,
the variables contain information about the operating environment that is used by the operating system and other programs
in various ways, typically to inform a program of the location of a certain piece of information it requires. A few examples follow:
• ComSpec, specifies the location of the command interpreter.
• PATH, specifies the locations to search for commands typed at the command line.
• Prompt, specifies how the command prompt should appear to the user.
• AGE, a user-defined variable for indicating the age of something.
• TEMP, specifies the directories where temporary files should be placed.
Auxiliary files for extended batch programming
Unfortunately, due to reasons unknown, many useful tools for batch programming have been omitted in recent versions of Windows
and are only available from within costly 'resource kits' that one has to purchase for seemingly extortionate sums of money.
However, there are free alternatives to some of these tools and/or hacks/kludges to circumvent their necessity.
Command Redirection and Pipelines
If you want to get help on a command in Windows, the usual way is to postfix the command with a space and then /?.
By default a normal command accepts input from standard input, which we abbreviate to stdin, standard input is the command line
in the form of arguments passed to the command. By default a normal command directs its output to standard output, which we
abbreviate to stdout, standard output is usually the console display. For some commands this may be the desired action but other
times we may wish to get our input for a command from somewhere other than stdin and direct our output to somewhere other
than stdout. This is done by redirection:
Creating Aliases
If you always use the same options to a command or would like to create an alias for a command with a certain set of options, why
not use a batch file to do so, simply create the batch file and place it somewhere in your path. Make sure that you do not create a
batch file with the same name as an actual command unless you really want to override the command if the batch file comes earlier
on in the PATH