• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Why Use the Magic Number in Qshell Scripts?

    March 17, 2004 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

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    Racksquared

    It’s time for IBM Power in the Cloud!

    Stop buying hardware and make the move to the cloud. It’s easier and more cost effective than you might think.

    • IBM Power in the Cloud
    • IBM Power Backup Solutions
    • IBM Power High Availability and DR solutions
    • IBM Power Colocation with Management and Monitoring

    Let’s talk about your business needs.

    Call: 855-380-7225
    Email: Sales@racksquared.com

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    DRV Technologies Expands Output Options with SpoolFlex 3.0 Power5 Debuts March 31, OS/400 V5R3 Coming in April

    Leave a Reply Cancel reply

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • IBM Tweaks Some Power Systems Prices Down, Others Up
  • Disaster Recovery: From OS/400 V5R3 To IBM i 7.4 In 36 Hours
  • The Disconnect In Modernization Planning And Execution
  • Superior Support: One Of The Reasons You Pay The Power Systems Premium
  • IBM i PTF Guide, Volume 25, Number 13
  • IBM i Has a Future ‘If Kept Up To Date,’ IDC Says
  • When You Need Us, We Are Ready To Do Grunt Work
  • Generative AI: Coming to an ERP Near You
  • Four Hundred Monitor, March 22
  • IBM i PTF Guide, Volume 25, Number 12

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2023 IT Jungle