next up previous contents
Next: Solutions to Exercises Up: Programming the Shell Previous: cutawk: Cut Selected

Exercises

  1. I have an IBM REXX emulator on my UNIX machine. I also have a set of REXX files I want to run. What should I do to those files in order to get them to run simply by typing their file name? Assume the REXX emulator is /usr/local/bin/rexx.
  2. Write a script that would display the time when run.
  3. Write a script that would wait 5 seconds, then display the time, but 5 seconds late. Hint: use the "sleep" command.
  4. Write a script that will take a person's name as a parameter to the program name. The script should greet that person, as
    Good Day name_entered, How are you today?
  5. Write a script that will prompt the user for a name. That same name will then be displayed in the same format as the previous exercise.
  6. Write a script that will return the number of parameters on the command line.
  7. Write a series of scripts that will count the number of parameters on the command line, first using the for statement, then the while and finally the until statement. (Three scripts).
  8. Write a script that will echo the third parameter, but only if it is present.
  9. Given a file of numbers (one per line), write a script that will find the lowest and highest number.
  10. Write a script that would recognize if a word entered from the keyboard started with an upper or lower case character or a digit. Use the "case" statement.

    The script would then output the word, followed by "upper case", "lower case", "digit", or "not upper, lower, or digit".

  11. Write a script that would first verify if file "myfile" exists. If if does not, create it, then ask the user for confirmation to erase it...
  12. Write a Bourne shell script to automatically compile your Fortran or C programs (prog.f or prog.c). The script should, if a name is not provided in the command line, prompt the user to input the program to be compiled. Hint: use awk -F. 'print $1'.
  13. Write a program that will calculate the amount of disk space your directory is using on the system.

    Hint: the program could use both the du and awk commands.

  14. Write a program that will list the files you have in the current directory, followed by the directories. The output should have the form:
            Files:
            ------
            filenames
    
            Directories:
            ------------
            directories
  15. Write a program to verify how many users are logged on to the system.
  16. Write a program that will take an undetermined list of parameters, and reverse them.
  17. Write a script that will accept any number of parameters. The program should display whether an odd or an even number of parameters was given.
  18. Write a script asking the user to input some numbers. The script should stop asking for numbers when the number 0 is entered. The output should look like:
    	user: logon_name
    
    	Lowest number entered:
    	Highest number entered:
    	Difference between the two:
    	Product of the two:
  19. Write a shell script that uses a temporary file to store the user name and the time the script starts. The script should run for approximately 30 seconds (use the "sleep" command). Run another occurrence of that same script, ensuring the temporary file used really has a unique name.

    The script should verify that the temporary file does not exist prior to attempting to use it.

  20. Write a script that changes the command line parameters to your own login id.
  21. Write a script that ignores any "CTRL-C". In fact, when "CTRL-C" is entered, it should display a message, then continue to run.
  22. Write a script that reads a "password" from a user (it will not show when typed, but will get displayed after the carriage return is entered).


next up previous contents
Next: Solutions to Exercises Up: Programming the Shell Previous: cutawk: Cut Selected

Claude Cantin
Sun Sep 1 02:02:26 EDT 2002