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 expansion,
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

Computer Science & Information Technology

You might also like to view...

________ is the operator for performing multiplication

Fill in the blank(s) with correct word

Computer Science & Information Technology

The newgrp command opens a new shell even if the command fails.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology