|
QShell for iSeries Authors: Holt T., Kulack F. A. Published year: 2003 Pages: 22-25/219 |
The EDTF editor is a general-purpose text editor you can use for creating and modifying Qshell scripts and other text files in the Integrated File System. It is not the only, or even the best, editor for entering Qshell scripts, howeverPC- based editors are much more powerful and do not sap system resources. Still, EDTF has the advantage that it is available on all OS/400-based systems.
As discussed in chapter 3, a Qshell script is a text file that contains commands that Qshell can interpret and execute. Because scripts are not compiled, but interpreted at run time, they might be compared to the OCL and REXX procedures that run on the iSeries.
You are probably accustomed to storing source code in source physical files. Qshell scripts may also be stored in source physical files, but they run faster and demand less system resources if they are stored in stream files in the root file system of the IFS.
In a production environment, Unix programmers and administrators typically store shell scripts in a /bin directory underneath a user 's home directory. You can follow that convention while learning to use Qshell and working through this book, but it's not necessary. All that matters is that you have a directory of your own.
A directory is like a source physical file, in that the directory can contain more than one instance of source code. A source physical file has members , while a directory has stream files . If you don't have your own directory and are not sure how to get one, see "Introducing the Stream-File Exercises" in chapter 3.
Although you can name a script file anything you want, it is probably a good idea to follow the conventions used in the Unix world. Unix script programmers typically begin with a base name . This may be followed by a period and a suffix to indicate the type of script. For example, a suffix of ksh indicates a Korn shell script.
The rules for naming files in the root system are very liberal . You may include blanks and punctuation marks in file names , but it is probably best not to do so. A good suffix for Qshell scripts is qsh, but that is by no means required.
The example scripts in this book often use the fictitious file name myscript.qsh . If you key some of the examples, you will probably want to use other names so you can keep more than one script on disk.
To run a Qshell script, enter its name on the command line of an interactive shell session and press the Enter key. Qshell may might respond with error 001-0019:
Error found searching for command myscript.qsh. No such path or
directory.
If you know that the file exists, the problem is likely that you do not have Execute permission or the PATH environment variable is not set correctly.
The PATH variable contains a list of directories that are to be searched for commands. To view the current setting of PATH, use the following command:
echo $PATH
Be sure to type the word PATH in uppercase letters , because Qshell variable names are case-sensitive.
Look for the name of the directory that contains your script. If your script is in the current directory, look for a leading colon, a trailing colon , two adjacent colons, or the current directory's name. Any of these indicates the presence of the current directory in the search path.
Every file has a set of permissions associated with it that tell who is allowed to read, write, and execute the file. Permissions are defined for the owner of the file, the group to which the owner belongs, and everybody else. Qshell scripts require Read and Execute permissions. (Permissions are discussed in detail in chapter 9.)
When you create an IFS file, you will probably have Read permission, but you may not have Execute permission. If not, you will have to grant yourself Execute permission in order to run the script.
Figure 4.1 shows how to determine and enable Execute permission within an interactive Qshell session. The - l option of the ls command displays a ten-character string that indicates the permissions. This string is in the first column of the output. The owner permissions are described by the second through fourth characters , which read rw - in this example. These characters indicate that the Read and Write attributes are enabled, but the Execute attribute is disabled. Notice the permissions after executing the chmod command. The hyphen in the fourth position has been replaced with an x . Now you can execute your script.
|
|
ls -l myscript.qsh -rw------- 1 JSMITH 0 25 Sep 3 09:05 myscript.qsh /home/JSMITH $ chmod u+x myscript.qsh /home/JSMITH $ ls -l myscript.qsh -rwx------ 1 JSMITH 0 25 Sep 3 09:05 myscript.qsh
|
|
|
QShell for iSeries Authors: Holt T., Kulack F. A. Published year: 2003 Pages: 22-25/219 |
![]() SQL for eServer i5 and iSeries | ![]() SQL Built-In Functions and Stored Procedures: The i5/iSeries Programmer's Guide | ![]() IBM System i APIs at Work | ![]() Advanced Integrated RPG |