how do I type a Q in a shell script to exit a status
I'm running a shell script and the q isn't exiting the screen. this is RHEL 7.9 I used to issue in VMS just fine but we have found that Linux scripts behave different. after these run I search the file for the status and depending on what it comes back with it will send an email.
if someone has anything better I'm listening
thanks
Paul
#!/bin/bash
TO_DAY=$(date +%A)
echo "Today is $TO_DAY"
#
touch /temp/CHECK_MIRROR_RPT.TXT
#
exec > /temp/CHECK_MIRROR_RPT.TXT
#
cache -U "%SYS" "Monitor^MIRROR"
q
#
Comments
q is the ObjectScript QUIT command, which exits the current context, but it is not the documented way to leave the ObjectScript shell itself. To exit the shell, enter HALT or H (case-insensitive). [1]
If your script is launching an InterSystems terminal session and waiting there, use HALT/H to return to the operating system prompt rather than q. [1]
If your goal is to have the shell script test a status afterward, one documented approach is to run the command through csession and then read the OS return code with $? in the shell. The example shown is:
csession $instance -U%SYS "##Class(Backup.General).ExternalFreeze()"
rc=$?
and then test rc in the shell script. [2]
That same discussion also shows that if you need to explicitly set an OS exit code from ObjectScript, you can use:
Do $System.Process.Terminate(,exitCode)
An older equivalent mentioned there is:
Do $zu(4,$job,exitCode)
So for your case, replacing the attempt to send q with an actual shell exit from ObjectScript (HALT/H for shell exit, or an explicit process termination with an exit code if needed) is the direction supported by the retrieved material. [1][2]
Sources:
You may need to explicitly send the quit command to the session. In shell scripts, using echo "q" | cache -U %SYS "Monitor^MIRROR" can work better because it passes the input directly to the process instead of waiting for interactive input.