Setup Bash on IBM i and Make it Friendly

This is part two of the posts I am putting together to help you get started using Open Source on IBM i. You can use the default shell; however, if you want an easier shell to work with, one that comes with history and more customization bash is the way to go. I started out using the default shell and it was very challenging for me. Even the command prompt in Windows has up-arrow history. If I typed a command wrong I had to start all over typing it again. Let’s just say that got old real quick. Enough talking let’s get down to business.

When I first connected to the system this is what it looked like. I received an error about my home directory not existing (I talked about this in my last post but wanted to cover it again). I created the directory and set the permissions using chmod.

Step 1: Switching from the Default Shell to Bash

There are 3 different options here: (these are taken from the IBM i BitBucket Repository — this site has a ton of great information)

  1. Set current user’s shell
  2. Set another user’s default shell
  3. Set the default shell for the system
-- set current user's shell
CALL QSYS2.SET_PASE_SHELL_INFO('*CURRENT', '/QOpenSys/pkgs/bin/bash');-- set a specific user's shell

-- (requires *SECADM special auth plus *USE and *OBJMGT to the user profile)
--***Change THATUSER to the username of the user profile that you want to configure***
CALL QSYS2.SET_PASE_SHELL_INFO('THATUSER', '/QOpenSys/pkgs/bin/bash');-- set the default shell which is returned for users that do not have

-- (requires *SECADM special auth plus *USE and *OBJMGT to QSYS)
CALL QSYS2.SET_PASE_SHELL_INFO('*DEFAULT', '/QOpenSys/pkgs/bin/bash');

For testing and example purposes I ran CALL QSYS2.SET_PASE_SHELL_INFO(‘OPNSRCPGMR’, ‘/QOpenSys/pkgs/bin/bash’); in Run SQL Scripts. The OPNSRCPGMR user is the user I am using for my testing purposes.

Let’s try connecting to the system again.

Looks like bash to me! This gives us history and a better user experience; however, let’s go a step further. Josh Hall was kind enough to share this with me.

NOTE: This next step is optional. If you decide not to move forward and to stick with plain bash check out the part below about adjusting your PATH.

Step 2: A Better Bash Experience

Making these changes gives us an even better bash experience with better history, command line completion, git prompt, git bash completion, etc.

yum install yum-utils
yum-config-manager --add-repo http://rpms.sobo.red/ibmi/
yum clean metadata
yum install ibmi-dotfiles
ibmi-dotfiles

This installs additional utilities for repository management, sets the repo for several packages, and installs the ibmi-dotfiles. You can see in the screen shot below that the available packages now show the updated repository path.

Let’s try and run the first command.

yum install yum-utils

The first command I tried to run fails; that’s not good… This is because my PATH is not set to the open source environment. You can create a .profile document in your user’s home folder or you can set the path for this session or just cd to the path. I am going to use cd just to quickly show how to get this working. Ultimately, adjusting your path will save you time in the long run.

cd /qopensys/pkgs/bin
yum install yum-utils

The below screen shot was taken from the IBM i Bitbucket site found here. This explains how to configure your PATH.

Now that we have the first command in our better bash experience executed let’s move on to the rest.

yum-config-manager --add-repo http://rpms.sobo.red/ibmi/
yum clean metadata
yum install ibmi-dotfiles
ibmi-dotfiles

When we hit the yum install ibmi-dotfile we will be prompted to install them Y/N, type Y and hit enter.

You will see the Complete! message letting you know that it installed successfully.

Now to run our last command.

ibmi-dotfiles

You will be prompted to enter your name and email for use with Git.

Step 3: Open a new SSH terminal

Now we will see the changes.