Catalog / KornShell (ksh) Cheatsheet
KornShell (ksh) Cheatsheet
A quick reference guide for KornShell (ksh) scripting, covering essential syntax, commands, and features for efficient shell programming.
Ksh Basics & Syntax
Basic Syntax
#!/bin/ksh |
Shebang line, specifies the interpreter for the script. |
Variable Assignment |
|
Variable Usage |
|
Command Substitution |
|
Comments |
|
Exit Status |
|
String Concatenation |
|
Input/Output
Reading Input |
|
Printing Output |
|
Redirecting Output |
|
Here Documents |
|
Variables
Types of Variables |
String variables (default), integer variables (using |
Exporting variables |
|
Unsetting a variable |
|
Special variables |
$0 (Script name), $1, $2, … (Arguments), $# (Number of arguments), $$ (Process ID) |
Control Flow
Conditional Statements (if/then/else)
|
Example:
|
Case Statements
|
Example:
|
Loops
For Loop |
Example: |
While Loop |
Example:
|
Until Loop |
|
Select Loop |
|
Functions and Arrays
Functions
Defining a Function |
or
|
Calling a Function |
|
Returning Values |
|
Local Variables |
|
Arrays
Declaring an Array |
|
Assigning Values |
|
Accessing Elements |
|
Array Length |
|
All Elements |
|
String Manipulation and Built-in Commands
String Manipulation
Substring Extraction |
|
String Length |
|
Pattern Replacement |
|
Case Conversion |
|
Built-in Commands
|
Print working directory |
|
Change directory |
|
List files and directories |
|
Create directory |
|
Remove file |
|
Copy file |
|
Move or rename file |
|
Evaluate expression (used in conditionals) |