Newsletters   Subscriptions  Forums  Store  Media Kit  About Us  Contact  Search   Home 
fhg
Volume 4, Number 8 -- March 17, 2004

Why Use the Magic Number in Qshell Scripts?


Hey, Ted:

I have not worked with Unix, so Qshell is a new adventure for me. I am curious about the "magic number," the #! comment that shell scripts typically begin with. It appears to me that Qshell doesn't care whether you include the comment. Is that true? If so, is there a reason why I should include the magic number?

--Jim


It's true. Take a look at the process Qshell goes through to execute a script.

When you type a script name and press Enter, Qshell starts a new job and asks the system to run the script. The system reads the first line of the script to see whether it contains the magic number. If the system finds the magic number, it loads the executable file named in the magic number, passing the name of the script to the executable file in the first positional parameter. Suppose the first line of script file Example, located in directory /home, contains the following magic number.

#! /usr/bin/qsh

The system runs the following command:

/usr/bin/qsh /home/Example

The result is that the system loads Qshell and runs the script, which is what you wanted.

Now suppose that the magic number is omitted. The system reads the first line of the script but does not find a magic number. In this case, the system invokes Qshell anyway, passing it the script file name in the first parameter. Qshell attempts to run the script.

This brings us back to your question. If Qshell ends up running the script anyway, why should you include the magic number? In your situation, it may not matter. I can think of a couple of reasons why it's a good idea to use the magic number.

First, the magic number leaves no doubt that the script was written for Qshell. Scripts written for PASE shells can run a Qshell script simply by executing the Qshell script file name.

Second, whatever your feelings for Unix and Linux are, the fact is that use of these operating systems is growing in iSeries shops. Chances are good you'll have to work with either or both of them, and you will need to include the magic number in scripts written for those environments. Why not adopt the practice now?

--Ted

Sponsored By
ITERA

High Availability
That's Affordable, Reliable, Easy-to-Use

State-of-the-art high availability isn't as expensive and complex as you think. Not only does Echo2 cost about half of other solutions, it is so dependable, automated and self-managing that monitoring of the system usually takes less than an hour a day, and production-to-backup switchovers can be reliably accomplished in minutes.

For the Free White Paper, "High Availability - It's More Affordable Than You Think,"
call 1-800-957-4511, email to info@iterainc.com, or visit www.iterainc.com.


Editors: Howard Arner, Joe Hertvik, Ted Holt,
Shannon O'Donnell, Kevin Vandever
Managing Editor: Shannon Pastore
Contributing Editors: Raymond Everhart, G. Wayne Hawks,
Marc Logemann, David Morris
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message.

THIS ISSUE
SPONSORED BY:

Guild Companies
COMMON
iTera
WorksRight Sofware
Damon Technologies


BACK ISSUES

TABLE OF
CONTENTS
V5R3 CL Programming Enhancements, Part 1

Using 'New' SQL Data Types in RPG

Why Use the Magic Number in Qshell Scripts?

Admin Alert: The Absolute Coolness of the QNTC File System

OS/400 Alert: Major Outlook 2002 Vulnerability Discovered



Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.
Guild Companies, 50 Park Terrace East, Suite 8F, New York, NY 10034
Privacy Statement