IBM Support

Colorizing CSH or KSH Shell

How To


Summary

How to add color to the KSH or CSH shell environment

Objective

Steps

The ANSI standard defines the following colors.
The sequence is: \e[<NUM>m

Where <NUM> is one of:
Foreground:
30 Black
31 Red
32 Green
33 Yellow
34 Blue
35 Magenta
36 Cyan
37 White
Background:
40 Black
41 Red
42 Green
43 Yellow
44 Blue
45 Magenta
46 Cyan
47 White
0 Reset all
1 Bold
Shells handle escape sequences differently, so setting the right sequence requires research into the terminal, and shell requirements. Setting the escape first offers a more portable solution that can be quickly modified to apply to other shells.
The following syntax applies to csh:
csh:
set e="`echo x | tr x '\033'`"
set red="${e}[31m"
set green="${e}[32m"
set yellow="${e}[33m"
set blue="${e}[34m"
set magenta="${e}[35m"
set cyan="${e}[36m"
set white="${e}[37m"
set end="${e}[0m"
set prompt="${cyan}${LOGNAME}${blue}@`hostname`:${magenta}`pwd`> ${end}"
image-20220614140831-2

The syntax can be changed for ksh by replacing 'set' with 'export', and replacing 'prompt' with 'PS1'.

ksh:
export e="`echo x | tr x '\033'`"
export red="${e}[31m"
export green="${e}[32m"
export yellow="${e}[33m"
export blue="${e}[34m"
export magenta="${e}[35m"
export cyan="${e}[36m"
export white="${e}[37m"
export end="${e}[0m"
export PS1="${cyan}${LOGNAME}${blue}@`hostname`:${magenta}`pwd`> ${end}"

image-20220614141038-3

Tweak the syntax to suit your requirements.

For example , use '@${HOSTNAME}' instead of @`hostname` if HOSTNAME is defined in your environment)

export PS1="${cyan}${LOGNAME}${blue}@${HOSTNAME}:${magenta}$PWD> ${end}"

Additional Information

SUPPORT

If you require more assistance, use the following step-by-step instructions to contact IBM to open a case for software with an active and valid support contract.  

1. Document (or collect screen captures of) all symptoms, errors, and messages related to your issue.

2. Capture any logs or data relevant to the situation.

3. Contact IBM to open a case:

   -For electronic support, see the IBM Support Community:
     https://www.ibm.com/mysupport
   -If you require telephone support, see the web page:
      https://www.ibm.com/planetwide/

4. Provide a clear, concise description of the issue.

 - For guidance, see: Working with IBM AIX Support: Describing the problem.

5. If the system is accessible, collect a system snap, and upload all of the details and data for your case.

 - For guidance, see: Working with IBM AIX Support: Collecting snap data

[{"Line of Business":{"code":"LOB08","label":"Cognitive Systems"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SWG10","label":"AIX"},"ARM Category":[{"code":"a8m0z000000cw2mAAA","label":"Desktop-\u003EX11 Clients"}],"ARM Case Number":"TS004119103","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"All Version(s)"}]

Document Information

Modified date:
14 June 2022

UID

ibm16326209