USS and MVS switcheroo
Part Two - Challenge #14


As more and more young people are coming to work on the z/OS platform, they bring with them skills and conceptual ideas from other operating systems. One very popular operating system today is called Linux. Perhaps you've heard of it before?

Linux users are very familiar with the byte oriented command line interface (CLI) and the most commonly used shell for these users is something called the Bourne Again Shell, or "bash". Thankfully, we have bash in z/OS USS today, and many of you who have used bash in Linux will feel right at home here.

Not only is bash a nice interface to work in, it's also a programming language! For this reason, you can write series of bash commands in a file and then execute that file as needed.

Your challenge:

In this challenge, you explore the Unix System Services (USS) environment that you briefly interacted with in part one and delving deeper into bash programming.

You will need both your TN3270 client to connect to ISPF and your ssh client to connect to USS. Go ahead and connect to and log into both environments now.

At the USS prompt, enter the command you learned in part one to copy the file /z/public/hilow into your ~/bin directory.

hilow is a simple number guessing game that uses the read command to collect input from the user and compare it to a randomly selected number between 0 and 99, giving the user feedback and continuing to prompt for the answer until the guessed number matches the randomly selected number.

Once you have a copy of it, check to make sure that the executable bits are turned on and then try to execute it:

TEST008:/z/test008 > ls -la bin/hilow
-rwxr-xr-x   1 TEST008  IPGROUP      623 Sep  7 10:28 bin/hilow
TEST008:/z/test008 > which hilow
TEST008:/z/test008 > hilow
/z/test008/bin/hilow: line 7: unexpected EOF while looking for matching `)'
/z/test008/bin/hilow: line 29: syntax error: unexpected end of file

Aha! There exists at least one problem inside the script that bash dilligently reports as a missing close parenthesis on line 7. You must edit the hilow file and make the correction.

If you are familiar with the vi editor, you are welcome to use that directly from the bash prompt to edit. Sorry kiddo, no vim, emacs or nano here!

Teaching you vi is beyond the scope of this contest, so for the rest of you, leave the ssh shell connection open and switch to your TN3270 ISPF session. Open the Data Set List Utility (=3.4) and in the Dsname Level field, enter the path to your bin directory.

Dsname Level . . . /z/CC#####/bin
Note: Your unix home directory is all lowercase!

The ability to browse the USS file system directly inside the ISPF data set listing is a farily new feature in ISPF, so be sure to tell all your older z/OS friends about it!

Tab down to the command field next to the hilow file, and enter E to edit it. If you see an EDIT Entry dialog, simply press the Enter key again and the file will be opened for editing.

In the primary command field, enter HILITE AUTO then tab down to line 7.

Notice something strange here? The bash notation $(( ... )) means to perform some arithmetic and return the result. Here we use $$ to get the process ID (a semi-random integer value), and perform modular division over the biggest value (100). This results in generating a semi-random number between 0 and 99.

Fix the error and press F3 to save the file, then return to your bash prompt and attempt to run the hilow program again.

Here's a sample run after correcting line 7:

TEST008:/z/test008 > hilow
Guess? 50
You guessed 101
... smaller!
Guess? 25
You guessed 101
... smaller!
Guess? 1
You guessed 101
... smaller!
Guess? -1
You guessed 101
... smaller!
Guess? uhoh
You guessed 101
... smaller!
Guess? CEE5206S The signal SIGINT was received.

Something is still wrong, but not with the syntax. We have a runtime error! Press CTRL+C to send an interrupt signal and break out of the program.

Return to ISPF and edit the hilow program again. The bash command read is used to store the input from the user into a variable. Take a moment to think critically about what is happening here, and make the required change. Use F3 to exit the edit and save the file, then run the script again at the bash prompt.

Here's a successful run:

TEST008:/z/test008 > hilow
Guess? 50
You guessed 50
... bigger!
Guess? 75
You guessed 75
... smaller!
Guess? 62
You guessed 62
... smaller!
Guess? 56
You guessed 56
... bigger!
Guess? 59
You guessed 59
... bigger!
Guess? 60
You guessed 60
Right!! Guessed 60 in 6 guesses.

At this point, you can return to ISPF and run the following command to submit your work on this challenge:


You'll find the output from this challenge is stored in P2.OUTPUT(#14). Well done! You are quickly reaching the end of part two!

Next: Challenge #15