db2.sh: A Command Line Interface for DB2 on IBM i

Recently starting the IBM i BASH Tools repository has prompted me to think  of some scripts that would be useful. One that I have wanted for quite awhile is a Command Line Interface (CLI) for DB2 on the IBM i.

Calling DB2 from Command Line

Calling DB2 from the command line is done in the same way one would call any system command.

Repeatedly Asking for User Input Until Exit

Figuring out how to read user input repeatedly until exit turned out to be a little more complex than I anticipated, but it’s still a simple while loop.

Allowing for Input History

I wanted to allow the user to use the up and down arrows to cycle through the history of input. In order to do this, the input needs to be read in the while loop condition and history needs to be enabled for the input.

Db2.sh

Here’s the finished script:

Here it is in action:

Leave a Reply

Your email address will not be published. Required fields are marked *