Answer the question below:

a. Read the caution titled “Always quote positional parameters” on page 475
of Sobell. Use touch to create a file whose name has a SPACE in it. What hap-
pens when you give that filename as an argument to cptobak from the
previous step?
b. Modify the cptobak script from the previous step by quoting the positional
parameters in the cp line. Now what happens when you use the script to
make a copy of a file with a SPACE in its name?

a.
$ touch aa\ bb
$ ls -l aa*
-rw-rw-r-- 1 mark mark 0 Jan 15 16:35 aa bb
$ ./cptobak aa*
cp: target `bb.bak' is not a directory

The shell passes one argument (that includes a SPACE) to cptobak: aa bb. But
when the shell that is running cptobak parses $1, it expands it to two argu-
ments because it contains an unquoted SPACE; the shell passes to cp four
arguments:
cp aa bb aa bb.bak
When you pass more than two arguments to cp, the last argument must be
a directory: cp copies the files named by the first arguments into the direc-
tory named by the last argument. If the last argument is not a directory, cp
displays an error message.
b.
$ cat cptobak
...
cp "$1" "$1.bak"
$ ./cptobak aa*
$ ls aa*
aa bb aa bb.bak

Computer Science & Information Technology

You might also like to view...

Webcasts are only delivered as prerecorded audio and video content

Indicate whether the statement is true or false

Computer Science & Information Technology

A client has a computer that is infected with several viruses and spyware. Which of the following should the technician perform first before spyware removal?

a. Run the CHKDSK /R command b. Disable System Restore c. Disable network cards d. Run Windows Update

Computer Science & Information Technology