Write a sequence of commands or a script that demonstrates variable expansion occurs before pathname expansion.
What will be an ideal response?
The following sequence of commands demonstrates variable expansion
occurs before pathname expansion:
$ ls g?
g1 g2 g5 g8
$ a=g?
$ echo "$a"
g?
$ echo $a
g1 g2 g5 g8
Because neither single nor double quotation marks allow pathname expan-
sion, the first echo command displays the unexpanded argument g?. The
shell expands the variable but does not expand the pathname.
If pathname expansion occurred prior to variable expansion, the shell, in
the case of the second echo, would not treat the question mark as a special
character. After expansion, the argument that the shell passed to echo would
be g?, which echo would display.
Following is another example that demonstrates variable expansion occurs
before pathname expansion:
$ cat t1
touch /tmp/$1*
$ touch /tmp/hello
$ ls -l /tmp/hello
-rw-rw-r--. 1 max pubs 0 03-24 19:55 /tmp/hello
$ sleep 60
$ t1 h
$ ls -l /tmp/hello
-rw-rw-r--. 1 max pubs 0 03-24 19:56 /tmp/hello
You might also like to view...
________ allows more than one person to edit a document in a SharePoint document library
Fill in the blank(s) with correct word
In the box trace, each box contains all of the following EXCEPT ______.
a) the values of the references and primitive types of the method’s arguments b) the method’s local variables c) the method’s class variables d) a placeholder for the value returned by each recursive call from the current box e) the value of the method itself