Question
Question 7 You tested the preceding commands with a text file containing numbers, and you may have hand edited that file. Hand entering a list
Question 7
You tested the preceding commands with a text file containing numbers, and you may have hand edited that file. Hand entering a list of numbers is tedious and error prone, so of course, it can be automated:
The seq program outputs a sequence of numbers with optional separator characters. In fact, seq provides a cleaver way to automate calculations. For example, what is 20! (20 factorial)?
seq -s '*' 1 20 outputs
1*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18*19*20
Therefore, seq -s '*' 1 20 | bc outputs 20!: 2432902008176640000
bc is a handy Linux/Unix command line calculator.
If you want 20 random numbers in the range 1 to 100, you may use shuf -i 1-100 -n 20. [On Mac OS, the equivalent is jot -r 20 1 100]
Use shuf or jot in a pipeline with bc to calculate the sum of 1000 random numbers. Paste the command line you used in the answer field. hint: jot has a command line option to insert separators between numbers. hint: paste -sd+ inserts a '+' character between every line of its input.
Question 10 (1 point)
Shell meaning of different quotes
Review Section 3.1.2 "Quoting" of https://tiswww.case.edu/php/chet/bash/bashref.html
Escape character
As you may recall from learning Java or C/C++, the backslash character is an "escape" character that changed the meaning of the next character. It works the same way in Bash. If you want to use the literal quote character without starting or ending a newly quoted string, use \ e.g. "\"" is a string containing a " character. A \ at the end of a line tells the shell that the current command continues on the next line e.g.
cat a.txt b.txt \ c.txt > all.txt
Double quotes
from https://tiswww.case.edu/php/chet/bash/bashref.html
Enclosing characters in double quotes (") preserves the literal value of all characters within the quotes, with the exception of $, `, \, and, when history expansion is enabled, !. The backslash retains its special meaning only when followed by one of the following characters: $, `, ", \, or newline.
You have already used double quotes but may not have recognized the significance. Although it isn't mentioned in the above quote from the Bash Reference Guide, double quotes are used for "grouping".
For example, in the command, echo "John Q. Public", the three words, John, Q., and Public are treated as one argument (including the space characters) to echo.
Regular single quotes
from https://tiswww.case.edu/php/chet/bash/bashref.html
Enclosing characters in single quotes (') preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash.
You have already used single quotes but may not have recognized the significance. For example, when you executed seq -s '*' 1 20, the single quotes around * are necessary to prevent the shell from expanding the * meta-character with the names of every file in the current directory.
Back quotes
Back quotes a.k.a "back tics" tell the shell to evaluate everything between back quotes before the main command and pass the output of the back quoted commands as arguments to the main command as if you'd type that output at that place in the command line.
For example, the following command first executes cat names.txt and uses the output of cat as the command line arguments to ls -l. Only files with names listed in names.txt will listed.
ls -l `cat names.txt`
For a more interesting example, the following command concatenates all of the files named in authorBios.txt and writes the output to aboutTheAuthors.txt.
cat `cat authorBios.txt` > aboutTheAuthors.txt
Here is one more example using single quotes and back quotes that you'll actually use in the Lab that covers makefiles. This command automates the generation of complex charts from commands in command.txt and data in data.txt. wget is a program that downloads files from web services using Uniform Resource Locators (URLs). Google provides the "Google Charts" web service that accepts commands and data and returns a graphical chart(s). Imagine that every week, you want to produce a new chart showing product sales for the previous week. The regional offices each send sales data that you concatenate into data.txt. You then use the following command in a script that you run each week to produce the chart(s).
wget http://chart.apis.google.com/chart?`cat command.txt data.txt | tr -d ' '` -O chart.png
To answer this question, write commands that use each type of quote. You may use them all in one command line or use multiple command lines.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started