Which two statements are correct?

A user jack, using a korn shell, requests a directory listing as follows:
jack@solaris:/export/home/jack $ 1s
File filea Filea fileb Fileb filec Filec
Which two statements are correct?

A user jack, using a korn shell, requests a directory listing as follows:
jack@solaris:/export/home/jack $ 1s
File filea Filea fileb Fileb filec Filec
Which two statements are correct?

A.
The pattern [?i]*a will expand to filea Filea.

B.
The pattern [fF]*a? will expand to [fF] *a?.

C.
The pattern [gfe] * will expand to file filea fileb filec.

D.
The pattern [g-e] * will expand to file filea fileb filec.

E.
The pattern [fF] [a-zA-z] i*e will expand to file.

Explanation:
A: starting with one single character, second character must be letter i, any
characters, ending with letter a.
C: starting with letter e, f, or g, followed by anything.



Leave a Reply 5

Your email address will not be published. Required fields are marked *

5 × four =


rocky

rocky

A is wrong because one cannot use “?” in posix character classes.
D is wrong because you can use only [e-g]*. [g-e] in reversed order is not allowed in posix cc.
E us wrong because it would match anything like “faile,Fcile,Fcilllle fFile FFile or fgimme” but it would never match to “file”. “file” indeed does not exist in the first ls in the example.
so only B and C is correct. – assuming that “file” doesn’t mean a file name here.

root@solaris:~# ls
File filea Filea fileb Fileb filec Filec
root@solaris:~# ls [?i]*a
[?i]*a: No such file or directory
root@solaris:~# ls [fF]*a?
[fF]*a?: No such file or directory
root@solaris:~# ls [gfe]*
filea fileb filec
root@solaris:~# ls [g-e]*
[g-e]*: No such file or directory
root@solaris:~# ls [fF][a-zA-z]i*e
[fF][a-zA-z]i*e: No such file or directory

andy

andy

Rocky is correct

greg

greg

I checked it on ksh shell and got the same result as you Rocky. I do not understand why you assumed that answer B is correct while it clearly shows error. Same on my system:

greg@gregsol:~/test$ ls
File filea Filea fileb Fileb filec Filec
greg@gregsol:~/test$ ls [fF]*a?
[fF]*a?: No such file or directory

This answer would fit if there won’t be a “?” at the end:

greg@gregsol:~/test$ ls [fF]*a
filea Filea

Clearly only answer “C” is correct:

greg@gregsol:~/test$ ls [gfe]*
filea fileb filec

So is the question formed incorrectly (one answer correct) or am I doing something wrong here?

rocky

rocky

Greg:
no, because there is the ? in the question, and no such file exists with this name, so will say, that [fF]*a?: No such file or directory.
Without the ? it would match to filea and Filea but the question does not states this. It states, that it expands to [fF]*a?. which is true, as there is no such file name like this.
Check this out:

rocky@solaris:~$ ksh
rocky@solaris:~$ touch \[fF\]*a?
rocky@solaris:~$ ls
[fF]*a? File filea Filea fileb Fileb filec Filec
rocky@solaris:~$ ls [fF]*a?
[fF]*a?
rocky@solaris:~$ rm \[fF]\*a\?
rocky@solaris:~$ ls [fF]*a?
[fF]*a?: No such file or directory rocky@solaris:~$

So I think in this form the question B is correct also.