× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi Patrik

I am going on memory but I've been doing a bit of this lately, so....
in CL if you want to insert a ' into a string then you need to double it
up. two '' get reduced to one ' (basically a quote is escaping a quote is
how I see it)
To produce a string echo 'thing' your input string would look like CHGVAR
VAR(&STR) VALUE('echo ''thing''') <- those are all single quotes!
Sometimes I use a variable &qt to make it easier so DCLVAR VAR(&QT)
VALUE('''') <- Thats 4 single quotes again! Two to denote a string and then
a quote escaped by a quote
Your example would look something like: CHGVAR VAR(&QSHDOIT) VALUE('echo'
*BCAT '''' *TCAT &MYSTR *TCAT '''' *TCAT '; echo $?') <- these are all
single quotes!
Or using my &QT example.. CHGVAR VAR(&QSHDOIT) VALUE('echo' *BCAT &QT
*TCAT &MYSTR *TCAT &QT *BCAT 'echo $?') - a lot more verbose but easier on
the eyes sometimes
Both of these should produce a string like: echo 'Hello'; echo $?
I think the earlier one would have produced this: echo Hello; echo$? (which
may work while you have a one word string)
I tend to build up my strings line by line rather than all in one go as CL
is a bit of a pain for building strings.
If you do a DMPCLPGM you can get a good look at your string.




On Wed, Aug 19, 2020 at 12:30 PM Patrik Schindler <poc@xxxxxxxxxx> wrote:

Hello,

I'm trying to dynamically assemble a string to be forwarded to QSH for
execution, but I'm most likely falling over the multiple apostrophes.

Actual CL program:

PGM
DCL VAR(&MYSTR) TYPE(*CHAR) LEN(5) VALUE('Hello')
DCL VAR(&QSHDOIT) TYPE(*CHAR) LEN(80)
CHGVAR VAR(&QSHDOIT) VALUE('echo'' *BCAT &MYSTR *CAT ''; echo $?')
QSH CMD(&QSHDOIT)
ENDPGM

Expected content of &QSHDOIT:
echo Hello; echo $?

Expected console output of qsh:
Hello
0

Instead, I get an error message stating, that there's no such command echo
*BCAT &MYSTR *CAT.

What am I doing wrong here? I remember there was a discussion about a
similar topic not too long ago, but I can't find it.

I hope, my mail client doesn't mess with the formatting.

Thanks!

:wq! PoC

PGP-Key: DDD3 4ABF 6413 38DE - https://www.pocnet.net/poc-key.asc


--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/midrange-l.

Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related
questions.

Help support midrange.com by shopping at amazon.com with our affiliate
link: https://amazon.midrange.com




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.