Guild Companies, Inc.  
 
Midrange Guru - Tech Tips
OS/400 Edition
Volume 2, Number 38 - May 17, 2002

Avoiding Split of a File Name Containing Blanks

Hey, Ted:

I'm new to Qshell script programming and enjoy your articles about the subject very much. So much, that I've started using Qshell when operating on stream files in the OS/400 IFS. I have encountered one problem though: files with one or more blanks in their name.

Here is an example:

files=$( ls *.csv )

for file in $files
do
 echo $file
done

The problem is in the for loop. When a file name contains blank(s), the variable file is first set with the first portion of the file name up to the first blank and the control block is done, then file is set to the next portion of the same file name.

I want to retrieve the whole name of the file, including blanks. How do I do that?

-- Christian

You've run into a powerful, but tricky, feature of the Qshell--globbing, or the expansion of expressions into lists of file names.

In your example, Christian, you use globbing in the first line to build a list of file names in the files variable. The file names are separated by one space. Therefore, if you have two csv files in your directory--a file.csv and cust.csv--the variable files takes this value:

a file.csv cust.csv

The for loop does not know that this is supposed to be a list of files and sees it as a list of three strings separated by blanks.

The solution to your problem is to delay globbing until the for loop executes:

for file in *.csv
do
 echo $file
done

-- Ted

Sponsored By
ADVANCED SYSTEMS CONCEPTS (ASC)

SEQUEL meets all your iSeries and AS/400 data access needs in a single, integrated solution:

  • Windows, Web or host user interfaces
  • Convert AS/400 data into PC file formats
  • E-mail or FTP query results, reports and spool files
  • Run-time prompted queries and reports for end users
  • IF-THEN-ELSE logic in queries and reports
  • Report, form and label formatting second to none
  • Easily convert date fields, character-to-numeric, numeric-to-character and other data manipulation
  • SORT or JOIN using a calculated field
  • Quick summarization of data with Tabling function
  • Run multiple SEQUEL requests as one with the SEQUEL Scripting function
  • OLAP Business Intelligence at a fraction of the cost of comparable solutions

Take 6 minutes to view a SEQUEL ViewPoint ScreenCam movie to see how simple Windows-based AS/400 and iSeries data access can be! In just a few short minutes, you can find out ways to make your job easier and improve data access throughout your organization. Download the ViewPoint movie here .

For more information or a FREE trial of SEQUEL, call 847/605-1311 or visit Advanced Systems Concepts .

THIS ISSUE
SPONSORED BY:
Advanced Systems Concepts (ASC)
TRAMENCO
BACK ISSUES
TABLE OF CONTENTS
Avoiding Split of a File Name Containing Blanks
Odds and Ends
Reader Feedback and Insights: OV/400 Data Text Merge
  Newsletters | Subscribe | Advertise | About Us | Contact | Search | Home  
  Last Updated: 5/17/02
Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.