Qshell for iSeries
From the basics of programming in the Qshell on iSeries to complete coverage of previously undocumented topics, programmers will not only learn the Qshell more easily than they can with the Qshell manual from IBM, they will also learn practical applications of using the Qshell effectively. Written for users who are more comfortable with DDS, CL, and RPG as well as those using modern languages such as C and Java, this book allows those who are unfamiliar with Unix to easily learn this technology, which otherwise might be foreign to them. Although written specifically for iSeries programmers, the information gleaned here will be largely applicable to the shells for Linux and Unix, so programmers not familiar with those platforms will find those shells much easier to learn after learning Qshell.
"1006178804"
Qshell for iSeries
From the basics of programming in the Qshell on iSeries to complete coverage of previously undocumented topics, programmers will not only learn the Qshell more easily than they can with the Qshell manual from IBM, they will also learn practical applications of using the Qshell effectively. Written for users who are more comfortable with DDS, CL, and RPG as well as those using modern languages such as C and Java, this book allows those who are unfamiliar with Unix to easily learn this technology, which otherwise might be foreign to them. Although written specifically for iSeries programmers, the information gleaned here will be largely applicable to the shells for Linux and Unix, so programmers not familiar with those platforms will find those shells much easier to learn after learning Qshell.
59.99 In Stock
Qshell for iSeries

Qshell for iSeries

Qshell for iSeries

Qshell for iSeries

eBook

$59.99  $79.99 Save 25% Current price is $59.99, Original price is $79.99. You Save 25%.

Available on Compatible NOOK devices, the free NOOK App and in My Digital Library.
WANT A NOOK?  Explore Now

Related collections and offers

LEND ME® See Details

Overview

From the basics of programming in the Qshell on iSeries to complete coverage of previously undocumented topics, programmers will not only learn the Qshell more easily than they can with the Qshell manual from IBM, they will also learn practical applications of using the Qshell effectively. Written for users who are more comfortable with DDS, CL, and RPG as well as those using modern languages such as C and Java, this book allows those who are unfamiliar with Unix to easily learn this technology, which otherwise might be foreign to them. Although written specifically for iSeries programmers, the information gleaned here will be largely applicable to the shells for Linux and Unix, so programmers not familiar with those platforms will find those shells much easier to learn after learning Qshell.

Product Details

ISBN-13: 9781583476918
Publisher: MC Press, LLC
Publication date: 03/01/2012
Sold by: Barnes & Noble
Format: eBook
Pages: 450
File size: 20 MB
Note: This product may take a few minutes to download.

About the Author

Ted Holt has worked in the information industry since 1981, primarily with IBM midrange computers. His industry experience includes the fields of manufacturing, healthcare, education, retail, and wholesale. He is the author of The MC Press Desktop Encyclopedia of Tips, Techniques, and Programming Practices for iSeries and AS/400, Complete CL, and Open Query File Magic. He lives in Corinth, Mississippi. Fred Kulack is an IBM developer who has implemented portions of many of the UNIX type API components on the iSeries. He has worked on Java and J2EE technologies like JDBC, the Java Transaction API, and WebSphere and was part of the team that developed the Qshell interpreter. He now helps large IBM business partners with architecture, porting, and performance related to their C, C++, Java, and J2EE applications. He lives in Rochester, Minnesota.

Read an Excerpt

Qshell for iSeries


By Ted Holt, Fred A. Kulack

MC Press

Copyright © 2004 MC Press Online, LP
All rights reserved.
ISBN: 978-1-58347-691-8



CHAPTER 1

Introduction to Qshell


A shell is a program that allows a human to interact with an operating system in a conversational way. The QCMD program that runs on the IBM iSeries 400 computer is a shell of sorts. DOS, the original operating system of the IBM PC, boots up to a shell called Command.com.


Unix and Linux Shells

Unix systems also have shell interfaces, but in the Unix world, there are several shells from which to choose. The Bourne shell, introduced in 1979, is the standard Unix shell, primarily used for system administration. It lacks many of the features of other, more recently developed shells, but is available on all Unix systems.

The C shell, which was developed at the University of California at Berkeley, is based on the C programming language. It is more powerful than the Bourne shell, and many programmers were quick to adopt it when it became available.

All other Unix shells are descendents of the Bourne and C shells. For example, David Korn developed the Korn shell in the mid-1980s as a superset of the Bourne shell. That is, the Korn shell is able to run scripts written for the Bourne shell, but the Bourne shell cannot run all scripts written for the Korn shell.

The invention of the Linux operating system brought about many new shells, but the two primary Linux shells are the Bourne-again shell (known as "bash"), based on the Bourne shell, and the TC shell, based on the C shell. These shells are now included with some Unix systems.

To facilitate the use of technology across platforms, two organizations have established standards for Unix shells. In 1986, the Institute of Electrical and Electronics Engineers (IEEE) released the Portable Operating System Interface (POSIX) standard for Unix systems. The POSIX standard is based on the Korn shell. The Open Group, a consortium of information-technology suppliers, created the X/Open standard as a superset of the POSIX standard. Qshell is based on both POSIX and X/Open standards.


Qshell

Qshell is a Unix-like interface to the IBM iSeries. It is a Boume-like shell, with many features from the Korn shell. Qshell began as a port of the ash shell, a Bourne-like shell from Berkeley Software Design (BSD). After the porting team had dealt with iSeries-specific issues like translation between ASCII and EBCDIC, they began adding features from other Unix shells. When a feature was implemented differently in different shells, the team followed POSIX standards.

Qshell consists of a command-line interpreter and a collection of utilities. The interpreter may be run in either interactive or batch mode. In interactive mode, it looks similar to the QCMD interface to OS/400.


The Need for Qshell

OS/400 already has the QCMD interface, a menu-driven interface, and iSeries Navigator (previously known as Operations Navigator). You might wonder, then, why there is a need for the Qshell interface. The answer lies in its unique benefits:

* Qshell includes commands that are not found in QCMD or iSeries Navigator, so it complements the other interfaces; it does not replace them.

* Qshell is well suited for working with the Integrated File System (the IFS), because the IFS is a hierarchical file system similar to those used on Unix systems.

* Qshell can run shell scripts from Unix platforms with little or no modification, so programmers from Unix systems can do productive work on the iSeries.

* Qshell handles multithreaded programming.

* Qshell is a good environment for creating Java applications.


Installing Qshell

Qshell is a licensed-program product that ships with OS/400. However, it is not mandatory that you install Qshell for OS/400 to operate.

To determine whether or not you have Qshell, use option 10 of the LICPGM menu. Look for an entry for the Qshell Interpreter, as shown in Figure 1.2.


If the Qshell interpreter is not listed as an installed program, load the system installation media and use option 11 to install Qshell. Page through the list of licensed programs until you see product option 30 (OS/400-Qshell Interpreter). Type 1 in the Option column of the Qshell Interpreter line as shown in Figure 1.3, and press Enter.

The system will ask you to confirm that you wish to install Qshell. Press the Enter key. You will see the Install Options display, pictured in Figure 1.4.

Ensure that your installation device is specified correctly depending on which CD or DVD drive you're using. Specify option 1 to install both programs and languages. Rebooting your iSeries is not required when installing Qshell, so specify an automatic IPL option of N. Press Enter to start the installation, and the system will begin installing Qshell.

You will know you are finished when you get the confirmation message shown in Figure 1.6. The Qshell interpreter is now ready for use.


Summary

Qshell adds a Unix-like interface to the iSeries. It is especially helpful for developing in Java and for working with the IFS. Once you have verified that Qshell is installed, you are ready to run it, which is the subject of the next chapter.

CHAPTER 2

Running Qshell


Use the "Start Qshell" CL command (STRQSH or QSH) to enter the Qshell environment. STRQSH has one parameter, CMD. The default value for CMD is *NONE, which means that no Qshell command is to be executed.

What happens when you run STRQSH depends on three things:

* Whether Qshell is running in a batch job or an interactive job

* Whether the CMD parameter specifies a Qshell command

* Whether Qshell is already active in an interactive job

The rest of this chapter examines these variations on STRQSH.


Qshell in an Interactive Job

If you start Qshell in an interactive job, and do not put a Qshell command in the CMD parameter, Qshell opens an interactive terminal session, as shown in Figure 2.1. If you use terminal services under Java, you will find this terminal session very familiar, since Qshell and Java use the same terminal support.


The Output Area

Below the panel title is the output area. When a Qshell session begins, the output area is blank except for the Qshell primary prompt string, which in Figure 2.1 is the value /home/SMITH $.

The dollar sign is a prompt character. Qshell uses four prompt characters, shown in Table 2.1, to indicate that it needs input. In chapter 9, you will learn how to change the values of these prompt characters. For example, you will be able to use a percent sign (%) instead of a dollar sign for the PS1 prompt character.

In the output area, Qshell lists the commands you give it and the response to those commands. Figure 2.2 shows part of the output area of an interactive Qshell session. First, the Is command tells Qshell to display a list of files whose names end with a period and the characters csv. Qshell responds with a list of three file names and the Qshell prompt, which in this session is set to the current directory followed by a dollar sign. The prompt informs the user that Qshell has completed the request and is ready for work.

The next command in Figure 2.2 is the rm, which removes directory entries. In this example, it deletes all CSV (comma-separated value) files.

The second ls command in Figure 2.2 lists files that end with .txt. Qshell responds with the appropriate list of file names and another Qshell prompt.


The Command Line

Below the output area is the command line, where you type the commands you want Qshell to carry out. Do not confuse this command line with a CL command line. You cannot directly execute CL commands from the Qshell command line. However, Qshell has a system utility you can use to execute CL commands.


The Function-Key Legend

Below the command line is the function-key legend. Table 2.2 describes the function keys that are active in the shell.


The CMD Parameter

You may specify a Qshell command up to 5,000 characters long in the CMD parameter of the STRQSH command. Here is an example:

STRQSH CMD('ls *.csv')


In this case, Qshell does not open a terminal session. Instead, it executes the Is command and ends.


If the command specified in the CMD parameter produces output, Qshell opens a temporary C runtime terminal session, as shown in Figure 2.3. You can also direct the output elsewhere, as discussed later in this chapter.

Input, however, is a different story. If you are running a script in this manner and Qshell encounters a request for terminal input, it ignores the request.


Qshell in Batch Jobs

You may also run Qshell in a batch job, within certain limits:

* Input requests are ignored.

* If the command produces output, Qshell spools the output.


The following example shows how to submit a Qshell command to run in batch mode:

SBMJOB CMD(QSH CMD('rm -f *.csv')) JOB(REMOVEFILE)


If the CMD parameter contains the value *NONE, Qshell does nothing and the job ends normally.


Redirecting Qshell Output

As of V5R2, you may use the QIBM_QSH_CMD_OUTPUT environment variable to control the destination of Qshell output. The allowable values are listed in Table 2.3.


In the following example of the QIBM_QSH_CMD_OUTPUT environment variable, the names of comma-delimited files are written to the file lsout.txt in the current directory, replacing any previous contents:

ADDENVVAR ENVVAR(QIBM_QSH_CMD_OUTPUT) VALUE('FILE=lsout.txt')
STRQSH CMD('ls *.csv')


As another example, the names of files that begin with a lowercase b are appended to the end of stream file lsout.txt, which is in the current directory:

ADDENVVAR ENVVAR(QIBM_QSH_CMD_OUTPUT)
VALUE(\FILEAPPEND=lsout.txt') STRQSH CMD('ls b*')


In both of these examples, output is sent to IFS files in the current directory. Writing to a stream file is generally the sensible approach. However, that is not to say that Qshell won't write to a database file. Here, the names of comma- delimited files are written to program-described database file, lsout, in the FILEINFO library:

ADDENVVAR ENVVAR(QIBM_QSH_CMD_OUTPUT) +
VALUE('FILE=/qsys.libfileinfo.lib/lsout.mbr')
CRTPF FILE(FILEINFO/LSOUT) RCDLEN(24)
STRQSH CMD('ls *.csv')


The output data is written to FILEINFO/lsout, ignoring record length. Each line of output is terminated by a hexadecimal-25 character.

To get a better idea of how output is written to database files, see Figure 2.4, which displays the Qshell output in character format, and Figure 2.5, which displays the output in hexadecimal format.


Processes

On Unix systems, a process is a running program. The Qshell interpreter is a process. Each utility that is not a builtin command runs in its own process. Scripts run in their own processes, unless they are invoked with the source (dot) utility.

Under Qshell, every process runs in its own job, so the terms process and job are interchangeable.


The Terminal Session

The terminal session appears to be an interactive session, but that is not entirely true. A terminal session is actually a combination of jobs.

When a user starts an interactive Qshell session, OS/400 starts a batch-immediate job running the Qshell interpreter, a program named QZSHSH. At this point, the user is running two jobs: the interactive job and the batch-immediate job.

You can use the Work with Active Jobs (WRKACTJOB) and Work with User Jobs CL command (WRKUSRJOBS) to see which jobs are running. The information returned by the WRKUSRJOB command is shown in Figure 2.6.


If you start a subshell or run a utility, Qshell will start additional jobs as needed. These have the name QP0ZSPWP, as shown in Figure 2.7.

Under V5R2, you can use Qshell's ps (Display Process Status) command to display information about processes. This command is illustrated in Figure 2.8.


Prestart Jobs

You can speed up processing by using a prestart job, which is a job that begins running when a subsystem is started. When Qshell starts a new process, it will use a prestart job if one is available. This improves performance, because the system does not have to start a new job.

Use the Add Prestart Job Entry (ADDPJE) command to create a prestart job. For example, the following command adds a prestart job to the QINTER subsystem description:

ADDPJE SBSD(QSYS/QINTER) PGM(QSYS/QPOZSPWP)
INLJOBS(10) THRESHOLD(5) ADLJOBS(10)
JOBD(QGPL/QDFTJOBD) MAXUSE(1) CLS(QGPL/QINTER)


To make Qshell use a prestart job, place a value of Y in the environment variable QSH_USE_PRESTART_JOBS. Use the export command so that child processes will also use prestart jobs:

export -s QSH_USE_PRESTART_JOBS=Y


A good place to put this command is in the /etc/profile special script file, which is discussed in chapter 4.


SUMMARY

The Qshell interpreter can run in both interactive and batch environments. In an interactive job, the user can enter commands for immediate execution.

Qshell executes commands in processes, which are implemented as jobs. You can improve the performance of Qshell commands by providing prestart jobs.

CHAPTER 3

The EDTF Text Editor


EDTF is a simple text editor that is designed for editing stream files. EDTF is a good choice for entering and modifying Qshell programs, known as scripts, in the Integrated File System (IFS). EDTF is not the only choice, however; you may instead use text editors on client computers. You can also use EDTF to edit database files, but it is not well suited for this purpose because it knows nothing about database field descriptions.


Starting EDTF

Use the Edit File CL command (EDTF) to invoke the editor. The EDTF editor has three parameters, which are described in Table 3.1.

You must run EDTF from a CL command line. It will not run from a Qshell command line. To get a CL command line within a Qshell session, press the F21 key.

Qshell scripts may be stored in database files, but they run faster when stored in the root file system of the IFS. All examples in this book assume that scripts are stored in the root, so the FILE and MBR parameters will not be used here.

In Figure 3.1, file case02.qsh is being opened for editing from a CL command line.

Figure 3.2 shows the editing session. Notice that it is similar to the Source Entry Utility (SEU) in several ways:

* There is a command line at the top of the screen for file-level commands.

* Each line in the entry area is preceded by an area in which line commands may be typed.

* Most of the file-level and line commands are almost identical to corresponding SEU commands.

* Most of the display is an entry area, in which you enter the text of the file.

* Most of the EDTF function-key assignments are identical to corresponding assignments in SEU.


However, there are quite a few differences as well. Here are some of the more obvious ones:

* EDTF is a much less robust editor than SEU and does not support nearly as many commands and editing options.

* Lines are not numbered in EDTF sessions.

* EDTF does not present an exit display when the F3 key is pressed.

* EDTF does not include formatted prompting.


The top line of Figure 3.2 shows that the name of the open file is case02.qsh. The Record area on the second line indicates that the first record on the display is record 1 of the file. It also shows that there are 10 records in the file, and that the roll keys will page the display eight records at a time. The Column area on the second line in Figure 3.2 indicates that the first column on the display is column 1 of 59 columns in the record. Pressing F19 or F20 windows the display by 74 columns.

You may enter the commands shown in Table 3.2 in the Control area of the editing screen. Notice that most command names have two forms — a short one and a long one. The long forms are unnecessary, because the short names are easier to key.

Although the command names are capitalized in the table, they are actually not case-sensitive, so FIND, Find, and find are interchangeable. Parameters, on the other hand, are case-sensitive.

The find command accepts one parameter: a string for which to search. If the string includes blanks, surround it with single quotation marks or double quotation marks, as in the second of the following two examples:

f echo
f "Accounts payable"


(Continues...)

Excerpted from Qshell for iSeries by Ted Holt, Fred A. Kulack. Copyright © 2004 MC Press Online, LP. Excerpted by permission of MC Press.
All rights reserved. No part of this excerpt may be reproduced or reprinted without permission in writing from the publisher.
Excerpts are provided by Dial-A-Book Inc. solely for the personal use of visitors to this web site.

Table of Contents

Contents

Preface,
Chapter 1: Introduction to Qshell,
Chapter 2: Running Qshell,
Chapter 3: The EDTF Text Editor,
Chapter 4: Scripting,
Chapter 5: Parameters and Variables, Defined,
Chapter 6: Using Parameters and Variables,
Chapter 7: The Exit Status and DecisionMaking,
Chapter 8: Additional Control Structures,
Chapter 9: The Integrated File System,
Chapter 10: Input and Output,
Chapter 11: Command-Line Arguments,
Chapter 12: Commands,
Chapter 13: Functions,
Chapter 14: PathName Expansion,
Chapter 15: Scripts — Debugging, Signals, and Traps,
Chapter 16: Archives and Compression,
Chapter 17: Grep,
Chapter 18: Sed,
Chapter 19: Writing Programs for Qshell,
Chapter 20: Accessing OS/400-Specific Objects,
Chapter 21: Application Development Tools,
Chapter 22: The Perl Utility,
Chapter 23: Java Development Tools,
Chapter 24: C and C++ Development Tools,
Appendix A: Summary of Changes by Release,
Appendix B: Qshell Versus DOS,
Appendix C: Qshell and CL Commands for the IFS,

From the B&N Reads Blog

Customer Reviews