#!/bin/csh -f
# Example:    9.66

echo Hello ${LOGNAME}!
echo The hour is `date +%H`
echo "This machine is `uname -n`"
echo The calendar for this month is
cal 
echo The processes you are running are:
ps -ef | grep  "^ *$LOGNAME"
echo "Thanks for coming. See you soon\!\!"

#! /bin/csh  -f
# Example:    9.67

echo -n  "What is your name? " 
set name = $<
echo Greetings  to you, $name.

#!/bin/csh -f
# Example:    9.73

echo $0  $1 $2 $3
echo Welcome to this day `date | awk '{print $1, $2, $3}'`  
echo Hope you have a nice day, $argv[1]\!
echo Good-bye $argv[1] $argv[2] $argv[3]

#!/bin/csh -f
# Example:    9.80

echo  -n "What was your grade? "
set grade = $<
if ( $grade >= 90 && $grade <= 100 ) then
   echo "You got an A\!"
else if ( $grade > 79 ) then
   echo "You got a B"
else if ( $grade > 69 ) then
   echo "You're average"
else
   echo "Better study"
endif

#!/bin/csh -f
# Example:     9.89

if ( $#argv == 0 ) then
   echo "	Usage: $0  filename"
   exit 1
endif

set file = $1
if ( ! -e $file ) then
   echo "$file does not exist"
   exit 2
endif 

if ( -d $file ) then
   echo "$file is a directory" 
else if (-f $file) then 
   if ( -r $file && -x $file ) then      
   echo "You have read and execute permission on $file"	
   endif
else
   print "$file is neither a plain file nor a directory."
endif

#!/bin/csh -f
# Example:    9.91

echo "Your system type is: "
set release = (`uname -r`)
switch (`uname -s`)
case SunOS:
      switch ("$release")
      case 4.*:
	    echo "SunOS $release"
	    breaksw
      case [56].*: 
	    echo "Solaris $release"
	    breaksw
      endsw
      breaksw
case HP*:
      echo HP-UX
      breaksw
case Linux:
      echo Linux
      breaksw
endsw

#!/bin/csh -f
# Example:     9.90
echo -n "Which color do you like? "
set color = $<
switch ("$color")
case bl*:
   echo I feel $color
   echo The sky is $color
   breaksw 
case red:          # Is is red or is it yellow?       
case yellow:
   echo The sun is sometimes $color.
   breaksw
default:
   echo $color not one of the categories.
   breaksw                
endsw

#!/bin/csh -f
# Example:    9.93

foreach person (`cat maillist`)
   mail $person <<EOF
      Hi $person,
      How are you?  I've missed you. Come on over
      to my place. 
      Your pal,
	    $LOGNAME@`uname -n`
EOF
end

#!/bin/csh -f
# Example:     9.100
echo -n "What baseball hero died in August, 1995? "
set answer = $<
while ("$answer" !~ [Mm]*) 
   echo "Wrong\! Try again."
   set answer = $<
   if ( "$answer" =~  [Mm]* ) break 
end
echo "You are a scholar."
#!/bin/csh -f
# Example:     9.101

while (1)
   echo "Select a menu item"
   cat << EOF
      1) Append
      2) Delete
      3) Update
      4) Exit
EOF
   set choice = $<
   switch ($choice)
      case 1:
	 echo "Appending"
	 break           # Break out of loop; not a breaksw
      case 2:
	 echo "Deleting"
	 break
      case 3:
	 echo "Updating"
	 break
      case 4:
	 exit 0
      default:
	 echo "Invalid choice. Try again."
   endsw
end
echo "Program continues here"

----
#!/bin/csh -f

onintr int
echo "trapping interrupt for ls -l"
ls -l
        
echo "Interrupts disabled during ls -la"
onintr -
ls -la

echo "Business as usual for ls -lag"
onintr
ls -lag
exit 0          # Program finishes here.

int:
echo "ls -l interrupted"
exit 1



#! /bin/csh
# remove duplicate words from a file/list
if ( $#argv != 2) then
	echo "$0 requires two arguments, $0 infile outfile"
endif

set newlist
set oldlist = `cat $argv[1]`
foreach element ($oldlist)
	set flag = "on"
	foreach newelement ($newlist)
		if ( "$newelement" == "$element" ) then
			set flag = "off"
			break	# found a duplicate, get out
		endif
	end
	if ( "$flag" == "on") then
		set newlist = ($newlist $element)
	endif
end
echo $newlist > $argv[2]
exit 0



#! /bin/csh

set totalwords = 0
set line = $<
while ("$line" != "" )
	set words = ($line)
	@ totalwords += $#words
	set line = $<
end
echo Total words : $totalwords



#! /bin/csh -f
set _which_saved_path_ = ( $path )
set prompt = ""
if ( -r ~/.cshrc && -f ~/.cshrc ) source ~/.cshrc
set path = ( $_which_saved_path_ )
unset prompt _which_saved_path_
set noglob
foreach arg ( $argv )
    set myalias = `alias $arg`
    switch ( $#myalias )
        case 0 :
            breaksw
        case 1 :
            set arg = $myalias[1]
            breaksw
        default :
            echo ${arg}: "      " aliased to $myalias
            continue
    endsw
    unset found
    if ( "$arg:h" != "$arg:t" ) then            # head != tail, don't search
        if ( -e $arg ) then                     # just do simple lookup
            echo $arg
        else
            echo $arg not found
        endif
        continue
    else
        foreach i ( $path )
            if ( -x $i/$arg && ! -d $i/$arg ) then
                echo $i/$arg
                set found
                break
            endif
        end
    endif
    if ( ! $?found ) then
        echo no $arg in $path
    endif
end
