in Operating System edited by
2,235 views
2 votes
2 votes

What will be the output of the following Unix command?

$\text{\$ rm chap0[1-3]}$

  1. Remove file $\text{chap0[1-3]}$
  2. Remove file $\text{chap01, chap02, chap03}$
  3. Remove file $\text{chap [1-3]}$
  4. None of the above
in Operating System edited by
2.2k views

2 Answers

1 vote
1 vote

ans is A

Square brackets can surround a choice of single characters (i.e., one digit or one letter) you’d like to match. For example, [Cc]hapterwould match either Chapter or chapter, but [ch]apter would match either capter or hapter. Use a hyphen (-) to separate a range of consecutive characters. For example, chap[1-3] would match chap1,chap2, or chap3.

But if escape sequence(\) is used then it literally matches with that after \

so $rm chap0\[1-3\] will remove 

Remove file chap0[1-3]

 

edited by

2 Comments

what does '\' signify in chap0\ and [1-3\]
0
0
Will it not be option B according to your logic
0
0
1 vote
1 vote
Escape character in front of the brackets removes their meanings.

 

Hence it just deletes a file named chap0[1-3]
Answer:

Related questions