Project 3

Shell and Sub-shell Exercise

  1. Define a shell variable called myName and assign your first name to the variable.
  2. Display a list of all shell variables, pipe the output to the grep command to search for them myName variable.
  3. Use the echo command to display the name of the variable.
  4. Use the echo command to display the value of the variable.
  5. Create a file using the touch command by referencing the value of the myName variable as the filename parameter to the touch command.
  6. Assign your full name to the myName variable and then display the name of the variable and the value of the variable (e.g., myName  = fred flintstone).
  7. Create another shell variable called myMessage and assign the value to the message so that the message, “Welcome yourname” appears when you display the value of the myMessage variable. Reference the value of the myName variable to get the value defined for your full name.
  8. Create an alias called lap to display all of the current running processes whose command name contains the value of the first parameter passed into the command. Use this alias to display all bash processes.
  9. What is the difference between double quoting, single quoting and back quoting the value of a command?
  10. Define a variable called dirContents, and assign to it the list of all files in the current directory. Display the value of the dirContents variable.
  11. Use the cat command to create a shell script. The shell script should have one input parameter. The shell script is to list all processes whose name contains the value of the input parameter. Execute the script to list all processes whose command name starts with the word “bash”.
  12. What are the differences between a shell and subshell? What does a subshell inherit and not inherit from the shell. How can you share the value of a variable defined in the shell with a subshell process? What is the scope of a normal shell variable vs. an environment variable?
  13. Make the myName variable an environment variable.
  14. Create a shell script called, testEnvVar, to display the variable name followed by the value of the variable for the following variables, myName, myMessage.  Change the permissions to execute the shell script and execute the testEnvVar script. Why was not value displayed for the myMessage variable?
  15. Why is it a good idea to change the permissions on a shell script to execute it as oppose to use the sh or source commands or typing a period followed by the command name?

© 2009 Roger K. Jackson

Published on October 7, 2009 at 9:29 pm Leave a Comment

The URI to TrackBack this entry is: http://rkjacksonenterpriseapps.wordpress.com/project-3/trackback/