Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Jenny Matute Mr.

Patel NT1430 Homework Week 3 Explore and Discuss

Use the following keywords and phrases to help you locate appropriate resources: Bash scripts: is a file containing a list of commands to be executed by the bash shell. Bash history: a list of all commands with date and time. The Bourne shell: primary shell in scripts. It is a shell or command line interpreter for computer operating systems. Bourne again shell: is a free Unix shell that can be used in place of the Bourne shell Commands in Linux: there are two types of commands Shell commands and Linux/Unix commands and are used to interact with the computer.

Questions /Exercises Chapter 7 1. What does the shell ordinarily do while a command is executing? What should you do if you dont want to wait for a command to finish before running another command?for the process to finish. Or sleeps. While the command is executing, the shell waits 2. What is a PID number? Why are these numbers useful when you run processes in the background? Which utility displays the PID numbers of the commands you are running? PID is a process identification number. Each of these numbers identifies the command running in the background. The utility that displays the PID numbers is ps 3. Assume that the following files are in the working directory: $ ls Intro notesb ref2 section1 section3 section4b Notesa ref1 ref3 section2 section4a sentrev

Give commands for each of the following using wildcards to express filenames with as few characters as possible. a. List all files that begin with section. $ ls section* b. List the section1, section2, and section3 files only. $ ls section[1-3] c. List the intro file only. $ ls i* d. List the section1, section3, ref1, and ref3 files. $ ls *[13]

Give an example of a command that uses grep a. With both input and output redirected. $ grep \$Id < *.c > id_list b. With only input redirected. $ grep i suzi < addresss c. With only output redirected. $ grep il memo *.txt > memoranda_files d. Within a pipe. $ file/usr/bin/* | grep Again shell script | sort -r In which of the proceeding cases is grep used as a filter? Example d uses grep as filter.

Chapter 9 1. Explain the following unexpected results $ whereis date Date: /bin/date $ echo $PATH .:/usr/local/bin:/usr/bin:/bin $ cat > date echo This is my own version of date. $ ./date Sat May 21 11:45:49 PDT 2011

2. What are two ways you can execute a shell script when you do not have execute permission for the file containing the script? Can you execute a shell script if you do not have read permission for the file containing the script? 3. What is the porpuse of the PATH variable? a. Set the PATH variable so it causes the shell to search the following directories in order: /usr/local/bin /usr/bin /bin /usr/Kerberos/bin The bin directory in your home directory The working directory b. If there is a file named doit in /usr/bin and another file with the same name in your ~/bin directory, which one will be executed? Assume you have execute permission for both files. c. If your PATH variable is not set to search the working directory how can you execute a program located there? d. Which command can you use to add the directory /usr/games to the end of the list of directories in PATH? 4. Assume you have made the following assignment: $ person=zach Give the output of each of the following commands: a. echo $person b. echo $person c. echo $person 5. The following shell scripts add entries to a file named journal-file in your home directory. This script helps you keep track of phone conversations and meetings. $ cat journal # journal: add journal entries to the file # $HOME/journal-file file=$HOME/journal-file date >> $file echo n enter name of person or group: read name echo $name >> $file echo >> $file cat >> $file echo ---------------------------------------------- >> $file echo >> $file

a. What do you have to do to the script to be able to execute it? b. Why does the script use the read builtin the first time it accepts input from the terminal and the cat utility the second time? 6. Assume the /home/zach/grants/biblios and /home/zach/biblios directories exits. Specify Zachs working directory after he executes each sequence of commands. Explain what happens in each case. a. $ pwd /home/zach/grants $ CDPATH=$ (pwd) $ cd $ cd biblios b. $ pwd /home/zach/grants $ CDPATH=$ (pwd) $ cd $HOME/biblios 7. Name two ways you can identify the PID number of the login shell: 8. Enter the following command: $ sleep 30 | cat /etc/services Is there any output from sleep? Where does cat gets its input from? What has to happen before the shell displays a prompt? 9. Write a shell script that outputs the name of the shell executing it. 10. Explain the behavior of the following shell script: $ cat quote_demo twoliner=This is line 1. This is line 2. echo $twoliner echo $twoliner a. How many arguments does each echo command see in this script? b. Redefine the IFS shell variable so the output of the second echo Is the same as the first.

You might also like