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? Explain.
b. Redefine the IFS shell variable so the output of the second echo is the
same as the first.
The assignment statement assigns a string that contains a NEWLINE to the variable
twoliner. Because the NEWLINE is quoted, it does not end the command but rather
becomes part of the string assigned to twoliner. The first echo command
encloses the variable within quotation marks, causing the shell to interpret the
NEWLINE not as a special character but rather as itself. The echo command there-
fore displays two lines. The second echo command does not quote the variable.
The shell therefore interprets the NEWLINE as whitespace, causing echo to display
the string with a SPACE in place of the NEWLINE.
a. The first echo sees a single argument. Even though there are eight words
separated by SPACEs and a NEWLINE, echo’s argument is quoted, causing the
SPACEs and NEWLINE to lose their special meanings to the shell, which passes
the argument to echo. The second echo sees eight arguments, separated
by whitespace, because its argument is not quoted.
b. Put the following command at the beginning of the script:
$ IFS=x
When you assign the value of a character to IFS, you remove the value of
NEWLINE from the values of IFS. When NEWLINE is not a special character, the
shell always treats it (displays it) as a NEWLINE.
You might also like to view...
A _________ firewall configuration involves stand alone firewall devices plus host based firewalls working together under a central administrative control.
Fill in the blank(s) with the appropriate word(s).
An X Y (scatter) chart shows:
A) a relationship between two variables. B) values as percentages of the whole but may contain more than one data series. C) the high and low close prices for individual stocks over equal amounts of time. D) the trend of two variables using a minimum of two dimensions on a continuous line.
Discuss the two different control properties you can use to protect data on a form.
What will be an ideal response?
To move the pointer using a pointing stick, push the pointing stick with a finger.
Answer the following statement true (T) or false (F)