Hi Scot,
It works. Thank you for the successful answer.
Best regards,
Zvi
Hi Zvi,
The 'read' command isn't skipped, but when you invoke something via
QSH CMD('command-here') the session isn't considered an interactive session. STDIN is left closed, so when the 'read' utility tries to read from stdin, it gets an error, and the 'read' utility ends with a nonzero exit status.
For example, consider this trivial script:
printf "enter something:\n"
read X || X="error"
printf "I just read: %s\n" "$X"
If I run this script interactive, I get this:
QSH
$ ./myscript.sh
enter something:
blah blah
I just read: blah blah
If I run it with the 'cmd' parameter, I get this:
QSH CMD('./myscript.sh')
enter something:
I just read: error
So the 'read' utility is still running... but it's getting an error because STDIN isn't open. IBM's assumption is that if you use QSH CMD(xyz) you are running a command from a CL program, and don't actually want to start an interactive QShell session. So they don't allow scripts/programs/etc to read from the display.
If you _do_ want to have an interactive session where the user can interact with your script, try this:
PGM
ADDENVVAR ENVVAR(QIBM_QSH_INTERACTIVE_CMD) +
VALUE('myscript.sh; exit') +
REPLACE(*YES)
QSH
RMVENVVAR ENVVAR(QIBM_QSH_INTERACTIVE_CMD)
ENDPGM
In this case, it'll invoke QSH interactively, but it'll immediately run the interactive command specified in the QIBM_QSH_INTERACTIVE_CMD variable (which in this case consists of running your script, and then exiting QShell)
Removing the envvar is a good idea -- otherwise the next time someone runs QSH/STRQSH in the same job, the same command will run :)
--- On Tue, 12/28/10, Zvi Kave <zvi_kave@xxxxxxxxx> wrote:
From: Zvi Kave <zvi_kave@xxxxxxxxx>
Subject: QSH variable read failed
To: midrange-l@xxxxxxxxxxxx
Date: Tuesday, December 28, 2010, 7:22 AM
I am trying to get a variable from QSH script script.sh by command:
read varname
The "read varname" command line is in the script script.sh.
If I call the script by
QSH CMD('script.sh')
then the read command is skipped, and it does not wait for input from screen.
How can I fix it ?
Regards,
Zvi
As an Amazon Associate we earn from qualifying purchases.