What will be the output of the following Unix command ? $rm chap0\[1 - 3\]

2015

What will be the output of the following Unix command ?

$rm chap0\[1 - 3\]

  1. A.

    Remove file chap0[1 - 3]

  2. B.

    Remove file chap01,chap02, chap03

  3. C.

    Remove file chap\[1 - 3\]

  4. D.

    None of the above

Attempted by 41 students.

Show answer & explanation

Correct answer: A

Answer: The command removes a file named chap0[1 - 3].

Explanation:

  • Backslashes escape metacharacters: the backslashes before '[' and ']' tell the shell to treat those characters literally.

  • Escapes are removed by the shell before running the command, so rm receives the filename exactly as chap0[1 - 3] (no backslashes).

  • Because the brackets are escaped, the shell does not perform character-class expansion (globbing). Therefore it does not expand to chap01, chap02, chap03.

  • If the command had been written without escapes and without spaces as rm chap0[1-3], the shell would try to expand that pattern to matching filenames such as chap01 chap02 chap03.

Explore the full course: Nta Ugc Net Paper 2

Loading lesson…