• 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
    Raz-Lee Security

    Start your Road to Zero Trust!

    Firewall Network security, controlling Exit Points, Open DB’s and SSH. Rule Wizards and graphical BI.

    Request Demo

    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

    • Positive News From The Kyndryl Mainframe Modernization Report
    • NAViGATE, inPower 2025 On Tap for September 2025
    • Guru: WCA4i And Granite – Because You’ve Got Bigger Things To Build
    • As I See It: Digital Coup
    • IBM i PTF Guide, Volume 27, Number 37
    • 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

    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