Question

1.) If the commands below will be executed in order, determine the output of the 4 echo commands (labeled as A-D): (2 Marks)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

i) Let's see the execution first and then output followed by explanation :

  $ r=7 ~$ export b=9 ~$ echo $r 7 ~$ sh $ g=3 $ echo $b 9 $ b=8 $ bash ~$ echo $g ~$ exit exit $ echo $b 8 $ exit

As above run window shows, we will go through oututs and their explanations,

A) As we have set the value of r as 7 in same shell, output will be 7.

B) Even though we have changed shell after executing A, as we had exported value of b = 9, in sh also, it will output the same value as 9.

C) After that, we are going back to bash shell, so since we had set value of g in sh shell, bash will have no value of variable g hence output is blank.

D) After exiting from bash, we areback to shell sh where we had set b=8, hence output of command D is 8.

ii) I have inputted the whole text file as below in shell for better demonstration :

 ~/Ashu$ cat table 2 Services 7 1 Executive Summary 5 1.1 Objectives 6 1.2 Mission 6 6 Financial Plan 14 6.1 Important Assumptions 14 Startup Funding Requirements 15 6.1.1. Other Current Assets 16 6.2 Break even Analysis 16 Appendix 12-Month Sales Forecast(12 Month Detail) 21 12-Month Personal Forecast(12-Month Detail) 22 12-Month Profit & Loss Forecast(12-Month Detail) 23 ~/Ashu$ 

Now we can proceed with commands and their outputs :

a)  head -2 table |sort -k3 -n

 ~/Ashu$ head -2 table |sort -k3 -n 1 Executive Summary 5 2 Services 7

head -2 table prints the first two lines of the file while sort -k3 -n sorts the output on the basis of third column numerically.

b) sed -n '/Appendix/{=; q;}' table

 ~/Ashu$ sed -n '/Appendix/{=; q;}' table  10

Above command counts the number of lines using sed until certain pattern is foound. As the requirement was to include the Appendix line the count is 10.

c)  sed -n '/Executive Summary/,/Financial Plan/p' table | head -n -1| tail -n +2 | tr '[:upper:]' '[:lower:]' > content.out

 ~/Ashu$ sed -n '/Executive Summary/,/Financial Plan/p' table | head -n -1| tail -n +2 | tr '[:upper:]' '[:lower:]' > content.out ~/Ashu$ ~/Ashu$ ~/Ashu$ cat content.out 1.1 objectives 6 1.2 mission 6

In above command,  sed -n '/Executive Summary/,/Financial Plan/p' table fetches the lines between given two patterns, head -n -1| tail -n +2 removes files including patterns, tr '[:upper:]' '[:lower:]' converts the case of Objectives and Mission to lowercase and finally > content.out redirects it to desired filename in currently working directory.

So in above way, we can achieve desired outputs.

Add a comment
Know the answer?
Add Answer to:
1.) If the commands below will be executed in order, determine the output of the 4...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • i.) If the commands below will be executed in order, determine the output of the 4...

    i.) If the commands below will be executed in order, determine the output of the 4 echo commands (labeled as A-D): ( 2 Marks ) export z=3 e=10 echo $e - A bash echo $z -B k=4 sh Z=7 echo $k -C exit exit echo $z -D ii.) Given the contents of file (filename: /home/user5/research) below, write the single command line needed to perform the following tasks. SUMMARY GLOSSARY CHAPTER 1 Introduction and Research Approach Reach Obiective REFERENCES APPENDIX A...

  • Round 1: sequence.c This program should read and execute a list of commands from stdin. Each comm...

    Round 1: sequence.c This program should read and execute a list of commands from stdin. Each command and its arguments (if any) will appear on a separate line. For example, if the file "cmdfile" contains the lines: whoami cal 4 2019 echo The time is: date then running 1 /sequence< cmdfile should output your username, a calendar of the month of April, the string "The time is:", and the current date/time, to standard output. Suggested approach: first, make sure you...

  • 1. Write 4 simple shell scripts. Each question will ask you to write one or more...

    1. Write 4 simple shell scripts. Each question will ask you to write one or more command lines to solve a problem. Put the command(s) from each problem into a file named problem1.sh, problem2.sh Note that if you want your script to be interpreted by bash, each file should start with the line: #!/bin/bash and will have one (or more, as needed) commands following it. To execute each script in bash, so you can determine if it is working or...

  • 1) Write a Unix command that will display the message below using echo and the value...

    1) Write a Unix command that will display the message below using echo and the value of your environment variable instead of the sample student login /students/astud01 My home directory is /students/astude01 2) Write a Unix command to display your login and the system date with both commands on one line (the output may be on separate lines) SAMPLE OUTPUT (details will differ): cconner Tue Jul 7 15:38:44 PDT 2015 3) 1.Write a Unix command that will redirect (>) the...

  • Objective : Write a C Shell script which copies all files(*.java and *.class) from your home dire...

    Objective : Write a C Shell script which copies all files(*.java and *.class) from your home directory to a new one, and Analyze the new directory information such as number of files, user permissions, and disk usage. Sample Output:                                                    << CS Directory Analysis >>      Date:   ============================================================ Current Directory: /home/tomss New Directory Created : /home/tomss/pgm01 File information Total Number of files : 22 files Directory files:   0 files Plain text files:   10 files File have read permissions: 3 files File have...

  • The purpose of this assignment is to develop solutions that perform File IO and objects. Problem specifications are shown below with my changes in blue. 1. File Previewer Write a program that asks...

    The purpose of this assignment is to develop solutions that perform File IO and objects. Problem specifications are shown below with my changes in blue. 1. File Previewer Write a program that asks the user for the name of a text file. The program should display the first 10 lines of the file on the screen. If the file has fewer than 10 lines, the entire file should be displayed along with a message indicating the entire file has been...

  • matlab 1. [suDmit as Iwo JPEGS in Canvas with your netiD in the title of each...

    matlab 1. [suDmit as Iwo JPEGS in Canvas with your netiD in the title of each plot] An electricity startup is looking into the viability of putting solar panels on the rooftops of buildings in Newark, NJ. They want you to help them come up with visualizations for data they have from the National Renewable Energy Laboratory and the National Oceanic and Atmospheric Administration about: - The average amount of sunshine received each month in the form of Global Horizonal...

  • c++ programming no use of classes use of functions pseudo code with comments Requirement: Provide one...

    c++ programming no use of classes use of functions pseudo code with comments Requirement: Provide one application for a business store that sale 2 models of one proo model FA218 and model FA318. The application first provides the menu to allow users can select one of the following tasks per time and when they finish one task, they can continue the application to select other task from the menu until they choose exit. All the output on the screen and...

  • 1 Overview and Background Many of the assignments in this course will introduce you to topics in ...

    1 Overview and Background Many of the assignments in this course will introduce you to topics in computational biology. You do not need to know anything about biology to do these assignments other than what is contained in the description itself. The objective of each assignment is for you to acquire certain particular skills or knowledge, and the choice of topic is independent of that objective. Sometimes the topics will be related to computational problems in biology, chemistry, or physics,...

  • Need help starting from question 9. I have tried multiple codes but the program says it is incorrect. Case Problem 1 Da...

    Need help starting from question 9. I have tried multiple codes but the program says it is incorrect. Case Problem 1 Data Files needed for this Case Problem: mi pricing_txt.html, mi_tables_txt.css, 2 CSS files, 3 PNG files, 1 TXT file, 1 TTF file, 1 WOFF file 0 Marlin Internet Luis Amador manages the website for Marlin Internet, an Internet service provider located in Crystal River, Florida. You have recently been hired to assist in the redesign of the company's website....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT