AS/400 Finally Gets a UNIX Face

UNIX / AIX
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Using Qshell, you can develop Java programs, run threaded programs, work with objects in the Integrated File System, and write scripts that run on other systems.

Starting with V3R1, the AS/400 has been adding functions based on industry standards from POSIX and X/Open. Even though the AS/400 now offers many APIs from these standards, it has been missing a UNIX-style shell interpreter and several utilities that go along with it. The shell and utilities combination provides a powerful scripting environment.

Qshell, a new feature of the AS/400 starting with V4R2, provides a UNIX-style command environment. The Qshell environment consists of two parts:

• The shell interpreter (or qsh) is a program that reads commands from an input source, interprets each command, and then runs the command by using the services of the operating system. The shell interpreter is similar to the command analyzer for CL. The Qshell Interpreter is option 30 of OS/400.

• The utilities or commands are external programs that provide additional functions and can be quite simple or very complex. The utilities are similar to CL commands. Qshell Utilities for the AS/400 (5799-XEH) is a PRPQ that includes 50 common utilities.

Background

A shell interpreter is a command line interface for working with the resources of a computer including programs, files, and devices. Every command-driven operating system has a shell interpreter. On AS/400s, the default shell interpreter is the command analyzer (or QCMD). On DOS and Windows, the command line interface is COMMAND.COM. On UNIX systems, there are many shell interpreters that have been developed over the years.

The Bourne shell (or simply sh) is the default shell that is provided with most UNIX systems. It is the oldest shell and is generally compatible across different systems. The C shell (or csh) provides a command language and syntax that is similar to the C programming language. It is a good interactive shell, but it is a weak shell for writing

scripts. The Korn shell (or ksh) is upwardly compatible with the Bourne shell, but it contains features that make it a good shell for both interactive use and writing scripts.

The shell and utilities are standardized with the POSIX 1003.2 standard. The standard is based on a 1988 version of the Korn shell. Since then, new versions of the Korn shell have been released with the last major update in 1993. There is also the Bourne Again Shell (or bash) that is based on the POSIX standard.

Qshell is the shell and utilities for the AS/400 based on the POSIX standard. It is compatible with the Bourne shell and many Korn shells. The Qshell Interpreter contains some features from the new Korn shell.

Reasons for Using Qshell

Qshell is an important addition to AS/400s for these reasons:
• Developing Java programs. The Java Development Kit (JDK), provided by Sun, includes 12 utilities for developing Java programs. The AS/400 Developer Kit for Java conforms to the Java standard, and, for that reason, these utilities are available only from Qshell. That means a Java developer can use the same utilities with the same interface on an AS/400 as they do on other systems.

• Running threaded programs. A threaded program can be developed in either Java or C by using the POSIX thread (Pthread) APIs. But a threaded program cannot start threads in an interactive job. The

Qshell command interface is implemented by using batch jobs, which can be multi-thread capable. So from the Qshell command line, you can run an interactive, threaded program.

• Working with objects in the Integrated File System (IFS). All of the utilities provided with Qshell are enabled for working with the IFS. This can make it easier to navigate in the many file systems in the IFS.

• Writing scripts that can run on other systems. Because Qshell is based on a POSIX standard, the shell scripts you write can run on other systems or scripts from other systems can be brought to the AS/400. Many new products are now providing common utilities. For example, the Directory Services option of OS/400, the Distributed Computing Environment (DCE) for AS/400 products, and the Net. Question products all provide Qshell utilities equivalent to the utilities in versions of their product for other systems. This allows a user or administrator of the product to have the same interface on different systems.

Qshell Language

The Qshell language is interpreted and is the same for both interactive use and writing scripts. The language is quite powerful and provides the following capabilities.

There are simple and compound commands. A simple command is just the name of a utility that you want to run. The shell interpreter searches for the command in the directories specified by the PATH environment variable. This is similar to the command analyzer searching the library list for a command.

The compound commands include the if-then-else conditional, case conditional, while loop, until loop, for loop, and functions. A function is a like a function or procedure from other programming languages. By using compound commands, you can write complex scripts using familiar programming constructs.

Redirections allow you to change where the input for a command comes from and where the output of the command goes. It is similar to an override in CL, but it can be much more powerful. For example, you can chain several commands together in a pipeline. This allows you to send the output from one command to the input of the next command. By using this technique, you can process the output from the first command through a sequence of other commands.

The shell interpreter also performs word expansions on its input. With a word expansion, the shell interpreter substitutes one string in the input for another string. Each word expansion is identified with a special character string. These are the expansions:

• A parameter expansion substitutes the value of a variable. A parameter expansion is specified by $(variable).

• A command substitution allows the output of a command to be substituted in place of the command name. A command substitution is specified by $(command).

• An arithmetic expansion evaluates a string as an integer arithmetic expression and substitutes its value. An arithmetic expansion is specified by $((expression)).

• A path name expansion substitutes a pattern for all of the files that match the pattern. This is like using a generic string in CL but is more powerful. A pattern is specified with the asterisk (*) to match all characters, the question mark (?) to match a single character, or brackets ([char]) to match a character class.

• A tilde expansion substitutes a tilde character with the user’s home directory. Only the Beginning Qshell provides a new environment for working with AS/400s where you can run UNIX utilities. Along with CL and Operations Navigator, it provides another interface for users on the AS/400. It also provides the base enablement for continuing to add new functions. For more information, see the Qshell Web site at www.ibm.com/as400/ developer/qshell.

BLOG COMMENTS POWERED BY DISQUS