• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Splitting a Qshell Variable

    August 7, 2002 Timothy Prickett Morgan

    Hey, Ted:

    I have two values, separated by a space, in one Qshell variable. I want to split them into two variables. Is there a way to do that?

    — Hank

    I know of one way. I’ll show it to you. It will make you appreciate that good old, antiquated RPG.

    Let’s say the two values are a first name and last name, stored in a variable called name, and that you want to put them into variables called first and last.

    First, let me give you the commands to split one variable into two. Then I’ll explain how it works.

    set $(echo $name | ( read fn ln ; echo $fn ; echo $ln ))
    first=$1
    last=$2
    

    The first echo copies the value of the name variable to the standard output file (stdout).

    The vertical bar tells Qshell that the output of the echo command is to be the input to the command that follows the vertical bar.

    The command that follows the vertical bar is a compound command, made up of three simple commands: one read and two echos. Qshell knows it’s a compound command because of the parentheses that surround it and the semicolons that separate the three simple commands.

    The read reads the piped output of the first echo command and divides it into two variables. Everything before the first space gets stored in variable fn. Everything after the first group of one or more spaces gets stored into variable ln. Variables fn and ln are only defined within the compound command.

    The last two echo commands send the values of fn and ln to standard output.

    Notice that most of the line is enclosed in a command substitution expression. A command substitution expression begins with a dollar sign ($) and open parenthesis and ends with a close parenthesis. (The use of an older syntax, which uses backquotes as delimiters, is discouraged in Unix circles.) The output of a command substitution expression is fed back into the currently executing Qshell command, which in this case is a set command.

    The set command, then, has two arguments–the first and last names that were extracted by the read. It stores them into positional parameters 1 and 2.

    Not exactly the epitome of intuitiveness, is it?

    The last two lines store the two positional parameters into variables called first and last.

    Maybe an example will help.

    Suppose variable name contains the value Joe Smith.

    • The first echo runs, sending the string Joe Smith into the pipeline.
    • The read command reads one record from the pipe, containing the value Joe Smith. Read stores Joe into variable fn and Smith into variable ln.
    • The second echo command sends Joe to stdout.
    • The third echo command sends Smith to stdout.
    • The set command is interpreted as follows: set Joe Smith. This action stores Joe in the first positional parameter and Smith in the second positional parameter.
    • The two assignment statements copy the first two positional parameters into variables first and last.

    — Ted

    Sponsored By
    WORKSRIGHT SOFTWARE

    On June 30, 2002,
    $$$$$$$$    Postal Rates went UP!    $$$$$$$$

    On July 1, 2002,
    $$$$$    you wanted your postage bill to go down.    $$$$$

    We have the solution! CASS certify your mailing names and addresses and presort your outgoing mail and save. Our CASS certification software ensures that your address files have valid ZIP Code and address information. Our presort software ensures that you can properly prepare you mail for delivery to your Post Office.

    WorksRight Software, Inc. is the number-one source for iSeries and AS/400 CASS, presort, ZIP Code, and area code software and data.

    Visit our Web site – www.worksright.com – to learn more about our CASS and presorting software, or contact WorksRight Software, Inc., phone 601-856-8337,
    e-mail software@worksright. com .

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags: Tags: mgo_rc, Volume 2, Number 59 -- August 7, 2002

    Sponsored by
    WorksRight Software

    Do you need area code information?
    Do you need ZIP Code information?
    Do you need ZIP+4 information?
    Do you need city name information?
    Do you need county information?
    Do you need a nearest dealer locator system?

    We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

    The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

    PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

    Just call us and we’ll arrange for 30 days FREE use of either ZIP/CITY or PER/ZIP4.

    WorksRight Software, Inc.
    Phone: 601-856-8337
    Fax: 601-856-9432
    Email: software@worksright.com
    Website: www.worksright.com

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Confirm File Deletions in Qshell TCP/IP Printing Problem

    Leave a Reply Cancel reply

MGO Volume: 2 Issue: 59

This Issue Sponsored By

    Table of Contents

    • Valuable Newsletters
    • Splitting a Qshell Variable
    • Tell PC5250 to Stop Bugging Me about My Password

    Content archive

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

    Recent Posts

    • AI Is Coming for ERP. How Will IBM i Respond?
    • The Power And Storage Price Wiggling Continues – Again
    • LaserVault Adds Multi-Path Support To ViTL
    • As I See It: Spacing Out
    • IBM i PTF Guide, Volume 27, Numbers 34, 35, And 36
    • The Power11 Transistor Count Discrepancies Explained – Sort Of
    • Is Your IBM i HA/DR Actually Tested – Or Just Installed?
    • Big Blue Delivers IBM i Customer Requests In ACS Update
    • New DbToo SDK Hooks RPG And Db2 For i To External Services
    • IBM i PTF Guide, Volume 27, Number 33

    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 © 2025 IT Jungle