• 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
    OCEAN User Group

    OCEAN TechCon25 Online

    It’s an Exciting Time for IBM i !

    July 16 & 17, 2025 – ONLINE

    Two virtual days of learning, presented by an outstanding group of IBM’ers and IBM Champions, featuring leading-edge topics.

    FREE for OCEAN members!

    Register NOW!

    Annual (12-month) Individual OCEAN Memberships are $80 and a Corporate Membership is $250. A Corporate Membership would allow your entire company to have full access to the OCEAN website & video library and to attend OCEAN events at member rates. Act now because rates are increasing on August 1, 2025.

    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

    • With Power11, Power Systems “Go To Eleven”
    • With Subscription Price, IBM i P20 And P30 Tiers Get Bigger Bundles
    • Izzi Buys CNX, Eyes Valence Port To System Z
    • IBM i Shops “Attacking” Security Concerns, Study Shows
    • IBM i PTF Guide, Volume 27, Number 26
    • Liam Allan Shares What’s Coming Next With Code For IBM i
    • From Stable To Scalable: Visual LANSA 16 Powers IBM i Growth – Launching July 8
    • VS Code Will Be The Heart Of The Modern IBM i Platform
    • The AS/400: A 37-Year-Old Dog That Loves To Learn New Tricks
    • IBM i PTF Guide, Volume 27, Number 25

    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