Stream files and shell commands

Work with the IFS and Qshell.

Keep stream files in the emulated filesystem and move source text between streams and members.

Directories and a text pipeline

Run these commands once in a fresh workspace. The shell writes fruit.txt relative to the CL job's current directory, sorts it and removes duplicate lines:

MKDIR DIR('/home/guide')
CD DIR('/home/guide')
QSH CMD('printf ''pear\napple\npear\n'' | sort | uniq > fruit.txt')
QSH CMD('cat fruit.txt; wc -l fruit.txt')
ADDLNK OBJ('fruit.txt') NEWLNK('fruit-link')
WRKLNK OBJ('/home/guide') DETAIL(*EXTENDED)

The result contains apple then pear, two lines. Directories, stream bytes, links and CCSID tags persist with the machine. The current directory belongs to the job; after signing on again, use CD to return. Changing directories does not change your current library. Root filesystem names are case-insensitive; names below /QOpenSys are case-sensitive.

Copy text to and from source members

CRTSRCPF FILE(QGPL/GUIDESRC) RCDLEN(112)
CPYFRMSTMF FROMSTMF('fruit.txt') TOMBR('/QSYS.LIB/QGPL.LIB/GUIDESRC.FILE/FRUIT.MBR')
CPYTOSTMF FROMMBR('/QSYS.LIB/QGPL.LIB/GUIDESRC.FILE/FRUIT.MBR') TOSTMF('roundtrip.txt') STMFCCSID(1208) ENDLINFMT(*LF)

The source file must exist. Copy-in generates source sequence/date fields and pads source records. Copy-out exports the member text as UTF-8 with LF line endings. Inspect FRUIT in PDM or use QSH CMD('cat roundtrip.txt'). Encoding and record-width choices matter: unsupported conversions fail explicitly. Generic IFS writes to QSYS.LIB are refused; use the member copy commands or FTP member transfer.

Run a CL command from Qshell

QSH CMD('system "DSPLIBL" | grep QGPL')

system runs CL in the emulator job and captures its messages/output. Qshell's cd changes only shell state, while CL CD changes the job's starting directory for subsequent QSH commands. QSH reports its exit status with QSH0005.

What the shell provides

Use quoting, variables, pipes, redirects, conditions, loops, functions and built-in text tools such as cat, grep, sort, uniq and basic sed/find. This is a bounded JavaScript interpreter over the emulator's IFS; it cannot launch host executables or access your computer's filesystem. Pipelines are buffered and sequential. Background processes, signals, here-documents and many utility options are unsupported. STRQSH without CMD does not open an interactive shell.

IFS owner/authority metadata is recorded, but complete IFS access-control enforcement is not implemented. For a portable archive of these streams and links, see IFS save/restore.