#!/usr/bin/csh ########################### # Name: array2.csh # Author: Jen Chen # Description: Create arrays in C-shell. # Date: 08/13/04 ########################### #Create an array of 5 elements: Apple, Banana, Cherry, Grape Fruit and Orange. #Note: If you'd like to store the words "Grape Fruits" as an element in an array #then enclose it in a pair of double quotes. Otherwise C-shell will treat it as #two different elements. #The array fruits has 5 elements. set fruits = ("Apple" "Banana" "Cherry" "Grape Fruit" "Orange") #The array fruits2 has 6 elements. set fruits2 = (Apple Banana Cherry Grape Fruit Orange) #Note the syntax: $#fruits returns the number of elements in the array fruits. echo "The array fruits has $#fruits elements." echo "The elements of the array fruits are:" set index = 1 while ($index <= $#fruits) #Loop through each element in the array fruits. #To access the elements in an array use the syntax: $array_name[$index]. echo "fruits[$index] = $fruits[$index]" #Print the elements on the screen. @ index = $index + 1 #increment the index. end set index2 = 1 echo echo "The array fruits2 has $#fruits2 elements." echo "The elements of the array fruits2 are:" while ($index2 <= $#fruits2) #Loop through each element in the array fruits. #To access the elements in an array use the syntax: $array_name[$index]. echo " fruits2[$index2] = $fruits2[$index2]" #Print the elements on the screen. @ index2 = $index2 + 1 #increment the index. end echo "The list of elements from the 3rd to the 5th in the array fruits are:" echo "$fruits[3-5]"