CS 497C - Quiz 4A - Name: ______________

Date: Friday, December 7 (in class)

Part 1: (20 points - 4 points for each problem)

(2) 1. Which command reveals details of users?
        (1) w (2) finger (3) who (4) detail

(2) 2. When using ftp, how do you list files in your local directory?
        (1) lls (2) !ls (3) lcd (4) !cd

(4) 3. If a script is run as foo -l -t bar[1-4], what is the value of $#?
        (1) 3 (2) 4 (3) 5 (4) 6

(1) 4. Which one is the here document?
        (1) << (2) >> (3) <1 (4) >1

(3) 5. To debug shell script, what is put into the beginning of the script?
        (1) set -dg (2) set -u (3) set -x (4) set -w

Part 2: (30 points - 6 points for each problem)

  1. What is a domain name? Give an example of a domain name.
    Ans: 1) A domain name locates an organization or other entity on the Internet. 
         2) www.cs.twsu.edu is a domain name.
    
  2. What is a port number for?
    In which file are known port numbers specified?
    Give an example.
    Ans: 1) A port number is a number which is used to identify a TCP/IP service. 
            Daemons listen for requests at certain specific port numbers assigned 
            to them.
         2) Know port numbers are defined in /etc/services.
         3) sendmail listens on port 25, ftp on 21 and telnet on 23. 
    
  3. How do you upload and download files in ftp?
    How do you set the transfer mode for a text file and an image file in ftp?
    Ans: 1) Use put or mput to upload. Use get or mget to download.
         2) Set ascii mode to transfer a text file and set binary mode to 
            transfer an image file.
    
  4. What will this statement do?
    filename=${1:-emp.lst}
    Ans: If a script is invoked without any argument, $1 would be null and
         filename would be set to emp.lst.
    
  5. Write a script to read in a number n as an argument and calculate the arithmetic summation 1 + 2 + 3 + 4 + .... + n.
    Ans: #!/bin/sh
         n=$1
         sum=$1
         while [ $n -gt 1 ]
         do
           n=`expr $n - 1`
           sum=`expr $sum + $n`
         done
         echo "Sum = $sum."