Question

In: Computer Science

Escaping At this point, there are four basic types of expansion the shell does for symbols:...

Escaping

At this point, there are four basic types of expansion the shell does for symbols:

  1. Variable expansion
  2. Command substitution
  3. Wildcard expansion
  4. Tilde expansion

Try it.

Try these examples of each type of expansion

$ echo $HOME         # variable expansion

$ echo $(whoami)     # command substitution

$ echo /etc/*.d      # wildcard expansion

$ echo ~leal      # tilde expansion

There are two types of escaping: partial quoting (double quotes) and full quoting (single quotes). Partial quoting escapes the content during some of these expansions, and full quoting escapes the content for all these.

Escaping

$variable expansion

$(command) substitution

*wildcard expansion

~tilde expansion

“partial quoting”

X

X

‘full quoting’

X

X

X

X

Consider the following examples:

$ echo $(whoami)     # normal command substitution

$ echo “$(whoami)”   # does not escape command substitution

$ echo ‘$(whoami)’   # escapes the command substitution

Loops

The bash for-loop has several variants. By default, it iterates over a list of values:

for i in 1 2 3

do

    echo “Hi $i”

done


We can also do this with a one-liner on the command line:

$ for i in 1 2 3; do echo “Hi $i”; done


Bash can also iterate over a sequence:

for i in {1..3}

do

    echo “Hi $i”

done


Bash can also iterate over a list resulting from an expansion:

for i in *

do

    echo “Hi $i”

done

Solutions

Expert Solution

1. The basic form of variable expansion is ${variable}. The value of variable is substituted.. The braces are required when variable is a positional variable with more than one digit, or when variable is followed by a character that is not to be interpreted as part of its name.

2. Command substitution allows the output of a command to replace the command itself. Bash performs the expansion by executing command and replacing the command substitution with the standard output of the command, with any trailing newlines deleted. Embedded newlines are not deleted, but they may be removed during word splitting.

3. Wildcards are useful in many ways for a GNU/Linux system and for various other uses. Commands can use wildcards to perform actions on more than one file at a time, or to find part of a phrase in a text file. There are many uses for wildcards, there are two different major ways that wildcards are used, they are globbing patterns/standard wildcards that are often used by the shell. The alternative is regular expressions, popular with many other commands and popular for use with text searching and manipulation.

4. The Bash shell provides some variables that are prefixed with ‘~’ known as Tilde Expansions.

Tilde expansion is the process of converting these abbreviations to the directory names that they stand for.
Tilde expansion applies to the ‘~’ plus characters includes +, – and N (which is integer) up to whitespace or a slash.The tilde expansion is used to expand to several specific pathnames:

  • Home directories
  • Current/previous working directory
  • Directories from directory stack.

Related Solutions

Supposing shell color in scallops is controlled by a single gene. Using appropriate symbols that you...
Supposing shell color in scallops is controlled by a single gene. Using appropriate symbols that you specify, please explain the following results by providing four Punnett Squares. Give a short explanation of your logic as needed. a. yellow shells X black shells produce ½ yellow offspring + ½ black offspring b. black shells X black shells produce 100% black offspring c. orange shells X orange shells produce ¾ orange offspring + ¼ black offspring d. yellow shells X orange shells...
What are the four basic types of contracts or instruments used in financial risk management?
What are the four basic types of contracts or instruments used in financial risk management?
Describe the four basic types of conflict and provide examples of each in a health care...
Describe the four basic types of conflict and provide examples of each in a health care environment. For each of the types of conflict, provide a type of negotiation that can be utilized effectively for resolution. Explain why you feel that each is the best type of negotiation in relation to the given conflict.
Describe the four basic types of production processes. What are the advantages and disadvantages of each?...
Describe the four basic types of production processes. What are the advantages and disadvantages of each? When should each be used?
3. Define the four basic types of trade barriers and give some examples of the arguments...
3. Define the four basic types of trade barriers and give some examples of the arguments in favor of protectionist policies.
According to the classic model, list and briefly define the four basic types of supervisory skills....
According to the classic model, list and briefly define the four basic types of supervisory skills. Which of these are of the most importance? Why? Question 1 options:
Isabel Myers was a pioneer in the study of personality types. She identified four basic personality...
Isabel Myers was a pioneer in the study of personality types. She identified four basic personality preferences that are described at length in the book Manual: A Guide to the Development and Use of the Myers-Briggs Type Indicator, by Myers and McCaulley.† Marriage counselors know that couples who have none of the four preferences in common may have a stormy marriage. A random sample of 375 married couples found that 295 had two or more personality preferences in common. In...
list the four basic organic molecule types, and for each, describe where it is first meaningfully...
list the four basic organic molecule types, and for each, describe where it is first meaningfully digested in humans and give the enzyme used to break it down.
What are the four basic types of international strategies that a company may pursue? Explain how...
What are the four basic types of international strategies that a company may pursue? Explain how the selection of one of these strategies is largely dependent on the relative pressure on the firm to address cost reduction and adaptation to local markets. Please be more detailed and more content
A point charge of -1C is placed in the center of a spherical shell of radius...
A point charge of -1C is placed in the center of a spherical shell of radius R and with surface charge density σ=1C/2πR^2.Calculate the magnitude of the electric field inside and outside the sphere. If a test charge q_0 was placed (inside and outside the sphere), what would be the magnitude of the force it would experience?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT