Newline Escape breaks piped command

Discussion of the free COZBATCH utility for z/OS
Post Reply
benjamin
Posts: 2
Joined: Tue Mar 06, 2018 3:00 am

Newline Escape breaks piped command

Post by benjamin » Tue Mar 06, 2018 3:30 am

Hello everyone!

I'm experiencing errors if I escape a newline in a piped command at positions which normally should work (outside JCL and COZBATCH).

Here is the working code:

Code: Select all

[JOBCARD]
// EXPORT  SYMLIST=(JP,RS)
// SET     JP='/somepath/tmp'
// SET     RS='somestringwhichshouldbereplaced'
// EXEC    PGM=COZBATCH,PARM='-LD'
//STEPLIB  DD DSN=DOS.COZBATCH.LOADLIB,DISP=SHR
//STDOUT   DD SYSOUT=*
//STDERR   DD SYSOUT=*
//STDIN    DD DATA,DLM=@@,SYMBOLS=JCLONLY
cp "&JP./somefile" "&JP./somefile.old"
cat "&JP./somefile.old" | \
    sed "s;^&RS.;\
#&RS.;" \
    > "&JP./lib/net.properties"
@@
Strangely, this three versions of the above code won't work:

Code: Select all

[...]
cat "&JP./somefile.old" | \
    sed "s;^&RS.;#&RS.;" \
    > "&JP./somefile"
@@

Code: Select all

[...]
cat "&JP./somefile.old" | \
    sed "s;^&RS.;\
#&RS.;" > "&JP./somefile"
@@

Code: Select all

[...]
cat "&JP./somefile.old" | \
    sed "s;^&RS.;#&RS.;" > "&JP./somefile"
@@
Does anybody know why?

Best,
Benjamin.

[edit] P.S. This is the error I got:

Code: Select all

CoZBatch[N]: Copyright (C) 2005-2013 Dovetailed Technologies LLC. All rights reserved.                           
CoZBatch[N]: version 3.5.1 2015-10-09                                                                            
CoZBatch[I]: executing progname=login-shell="-/bin/sh"                                                           
CoZBatch[E]: ./CoZBatch.C(268) - fgets(28609470,8192,2865E138) - [66] EDC5066I A read system error was detected. 
(errno2=0xC044000D)                                                                                              
CoZBatch[W]: an error occurred; returning rc=102                                                                 
Last edited by benjamin on Wed Mar 07, 2018 1:42 am, edited 1 time in total.

dovetail
Site Admin
Posts: 1850
Joined: Thu Jul 29, 2004 12:12 pm

Re: Newline Escape breaks piped command

Post by dovetail » Tue Mar 06, 2018 3:50 pm

If you add:

set -x

to the beginning of your shell script (DD:STDIN), you should be able to see what input that the shell is actually seeing.

Also: I think that there are advantages to using environment variables for the JES symbols, since you won't get into trouble with
input line length as you can with DD,SYMBOLS= substitution. COZBATCH will automatically set environment variables for all of your exported JES symbols. The envar name with have a "JES_" prefix.

See example 13 here: https://dovetail.com/docs/cozbatch/examples.html

So check, but in your case I think it would be something like:

//STDIN DD DATA,DLM=@@
cp "$JES_JP/somefile" "$JES_JP/somefile.old"
sed "s;^$JES_RS;\
#$JES_RS;" \
<"$JES_JP/somefile.old" \
>"$JES_JP/lib/net.properties"
@@

benjamin
Posts: 2
Joined: Tue Mar 06, 2018 3:00 am

Re: Newline Escape breaks piped command

Post by benjamin » Wed Mar 07, 2018 1:41 am

Thanks, using the '$JES_'-prefixes did the trick. Now I can write the code the way I'm used too (-8

For completeness:

Code: Select all

[JOBCARD]
// EXPORT  SYMLIST=(JP,RS)
// SET     JP='/somepath/tmp'
// SET     RS='somestringwhichshouldbereplaced'
// EXEC    PGM=COZBATCH,PARM='-LD'
//STEPLIB  DD DSN=DOS.COZBATCH.LOADLIB,DISP=SHR
//STDOUT   DD SYSOUT=*
//STDERR   DD SYSOUT=*
//STDIN    DD DATA,DLM=@@,SYMBOLS=JCLONLY
cp "$JES_JP/somefile" "$JES_JP/somefile.old"
cat "$JES_JP/somefile.old" | \
    sed "s;^$JES_RS;#$JES_RS;" > "$JES_JP/lib/net.properties"
@@

Post Reply