LiveFire Labs: Online UNIX Training with Hands-on Internet Lab


"Thank you for the use of your system and the lesson material on UNIX Shell scripting! I now have a firmer grasp on the Korn Shell as a whole, and give much credit to LiveFire Labs. Thank you again, and I will definitely consider your company in the future for anything else I may need!"

John M. Baughman
Synergetics Incorporated
Fort Collins, Colorado



... I bought a few Unix books but it did not help me much, so I was looking for a class that could teach me basic Unix shell scripting.

After research, LiveFire Labs was the only class that was affordable for me; other professional classes cost $1000+. I registered for the Unix Shell Scripting course and was able to work at home or office during my spare time. I liked the hands-on exercises, which are vital for learning programming skills. I recommend LiveFire Labs to anyone who wants to learn Unix skills.

Mike C. Wang
Long Beach, California

Read more student testimonials...

Demo ksh array Shell Script with Examples

DOWNLOAD our comprehensive ksh array shell script that demonstrates how to script the following shell array operations and more:
  • create/define a ksh array
  • assign values to a ksh array within a for loop, a while loop, or outside of a shell looping construct
  • determine array size and access array elements (values) using multiple methods
  • load the contents of disk files into ksh arrays
  • clear the contents of a ksh array
This script provides you with ksh array syntax examples and logic that you can incorporate into your own scripts.


Script Breakdown
  • 210 total lines
    • 1 shell definition line
    • 113 lines of shell script code
    • 49 comment lines to explain the script code and logic in detail
    • 47 blank lines for script readability

Script Output


NOTICE in the script's sample output below how it is broken down into multiple sections, each with a unique header, so that you can easily match (cross-reference) a section of output to the lines of code within the shell script that generated it.

For example, if you wanted to find the code section within the shell script that generated the output under the "output section F" header you would just search the shell script for "section F" to locate it.

The following is the output generated when the demo ksh shell array script is run...

$ clear; ./demo_ksh_array_shell_script


========================
=== output section A ===
========================

The value stored in FILENAME[0] is: contacts_family.txt
The value stored in FILENAME[1] is: contacts_friends.txt
The value stored in FILENAME[2] is: contacts_work.txt


========================
=== output section B ===
========================

There are 3 elements (values) in the FILENAME array, and the data stored in the array is:
contacts_family.txt contacts_friends.txt contacts_work.txt


========================
=== output section C ===
========================

There are 0 elements (values) in the FILENAME array, and the data stored in the array is:


========================
=== output section D ===
========================

The contents of the FILELISTING shell variable is:
contacts_family.txt
contacts_friends.txt
contacts_work.txt


========================
=== output section E ===
========================

The data in input file contacts_family.txt is:
SMITH TOM tom.smith@fam.com 512-123-4567
SMITH JANE jsmith@fam.com 512-123-0000
SMITH ROGER rogers@fam.com 512-456-1111

The data in input file contacts_friends.txt is:
JOHNSON BUCK bucky@friend.com 210-111-2222
SWANSON MARY marymary@friend.com 210-999-5555
SQUIDMAN LENNY thesquid@friend.com 210-833-1234

The data in input file contacts_work.txt is:
MOUSE MICKEY micky.mouse@thecorp.com 336-987-6543
SUBRAMANYA SRI ssubramanya@thecorp.com 336-408-6565
MARK MARKY marky@thecorp.com 336-222-3131


========================
=== output section F ===
========================

Storing contacts_family.txt into ksh array FILENAME element 0 or FILENAME[0]
Storing contacts_friends.txt into ksh array FILENAME element 1 or FILENAME[1]
Storing contacts_work.txt into ksh array FILENAME element 2 or FILENAME[2]

There are 3 elements (values) in the FILENAME array, and the data stored in the array is:
contacts_family.txt contacts_friends.txt contacts_work.txt


========================
=== output section G ===
========================

The value stored in ksh array FILENAME element 0 or FILENAME[0] is: contacts_family.txt
Loading the contents of contacts_family.txt to ksh arrays...
SMITH has been loaded to the LASTNAME array
TOM has been loaded to the FIRSTNAME array
tom.smith@fam.com has been loaded to the EMAIL array
512-123-4567 has been loaded to the PHONE array
SMITH has been loaded to the LASTNAME array
JANE has been loaded to the FIRSTNAME array
jsmith@fam.com has been loaded to the EMAIL array
512-123-0000 has been loaded to the PHONE array
SMITH has been loaded to the LASTNAME array
ROGER has been loaded to the FIRSTNAME array
rogers@fam.com has been loaded to the EMAIL array
512-456-1111 has been loaded to the PHONE array
Content load from contacts_family.txt is complete.

The value stored in ksh array FILENAME element 1 or FILENAME[1] is: contacts_friends.txt
Loading the contents of contacts_friends.txt to ksh arrays...
JOHNSON has been loaded to the LASTNAME array
BUCK has been loaded to the FIRSTNAME array
bucky@friend.com has been loaded to the EMAIL array
210-111-2222 has been loaded to the PHONE array
SWANSON has been loaded to the LASTNAME array
MARY has been loaded to the FIRSTNAME array
marymary@friend.com has been loaded to the EMAIL array
210-999-5555 has been loaded to the PHONE array
SQUIDMAN has been loaded to the LASTNAME array
LENNY has been loaded to the FIRSTNAME array
thesquid@friend.com has been loaded to the EMAIL array
210-833-1234 has been loaded to the PHONE array
Content load from contacts_friends.txt is complete.

The value stored in ksh array FILENAME element 2 or FILENAME[2] is: contacts_work.txt
Loading the contents of contacts_work.txt to ksh arrays...
MOUSE has been loaded to the LASTNAME array
MICKEY has been loaded to the FIRSTNAME array
micky.mouse@thecorp.com has been loaded to the EMAIL array
336-987-6543 has been loaded to the PHONE array
SUBRAMANYA has been loaded to the LASTNAME array
SRI has been loaded to the FIRSTNAME array
ssubramanya@thecorp.com has been loaded to the EMAIL array
336-408-6565 has been loaded to the PHONE array
MARK has been loaded to the LASTNAME array
MARKY has been loaded to the FIRSTNAME array
marky@thecorp.com has been loaded to the EMAIL array
336-222-3131 has been loaded to the PHONE array
Content load from contacts_work.txt is complete.


========================
=== output section H ===
========================

There are 9 elements in the LASTNAME array
LASTNAME[0] contains: SMITH
LASTNAME[1] contains: SMITH
LASTNAME[2] contains: SMITH
LASTNAME[3] contains: JOHNSON
LASTNAME[4] contains: SWANSON
LASTNAME[5] contains: SQUIDMAN
LASTNAME[6] contains: MOUSE
LASTNAME[7] contains: SUBRAMANYA
LASTNAME[8] contains: MARK

There are 9 elements in the FIRSTNAME array
FIRSTNAME[0] contains: TOM
FIRSTNAME[1] contains: JANE
FIRSTNAME[2] contains: ROGER
FIRSTNAME[3] contains: BUCK
FIRSTNAME[4] contains: MARY
FIRSTNAME[5] contains: LENNY
FIRSTNAME[6] contains: MICKEY
FIRSTNAME[7] contains: SRI
FIRSTNAME[8] contains: MARKY

There are 9 elements in the EMAIL array
EMAIL[0] contains: tom.smith@fam.com
EMAIL[1] contains: jsmith@fam.com
EMAIL[2] contains: rogers@fam.com
EMAIL[3] contains: bucky@friend.com
EMAIL[4] contains: marymary@friend.com
EMAIL[5] contains: thesquid@friend.com
EMAIL[6] contains: micky.mouse@thecorp.com
EMAIL[7] contains: ssubramanya@thecorp.com
EMAIL[8] contains: marky@thecorp.com

There are 9 elements in the PHONE array
PHONE[0] contains: 512-123-4567
PHONE[1] contains: 512-123-0000
PHONE[2] contains: 512-456-1111
PHONE[3] contains: 210-111-2222
PHONE[4] contains: 210-999-5555
PHONE[5] contains: 210-833-1234
PHONE[6] contains: 336-987-6543
PHONE[7] contains: 336-408-6565
PHONE[8] contains: 336-222-3131
$


DOWNLOAD the Script and its Supporting Data (Input) Files

To help support this site's ongoing effort to provide you with useful tools, tips and shell scripts such as the demo ksh array shell script, a nominal contribution of $0.99 is appreciated.




After the PayPal transaction completes a link to immediately download the demo ksh array shell script and its supporting data files will be provided.

Thank you for your support!!

Questions? Email us...










...or call 1.888.843.1637