A directory contains the following files:
a.txt
b.txt
c.csv
What would be the output of the following shell script?
for file in *.txt
do
echo $file
done
a.txt b.txt
The shell script iterates over all files in the current directory that match the pattern `*.txt`, and it outputs each of these files' names. Since there are two `.txt` files present, the output will include both of them.
This choice represents a wildcard pattern rather than the actual filenames. In the context of the script, the `for` loop will not output the wildcard itself; it matches specific files instead.
This answer omits the file extensions and does not accurately reflect the actual output of the script. The script will print the full names of the files, including their extensions, which are `a.txt` and `b.txt`.
This choice is incorrect because `c.csv` does not meet the criteria specified in the loop for files ending with `.txt`. Therefore, it will not be included in the output.
While `a.txt` is one of the files that will be printed, this choice incorrectly suggests that only one file will be output. The script processes all matching files, so both `a.txt` and `b.txt` will be echoed.
The script's purpose is to list all `.txt` files in the directory. Since it finds both `a.txt` and `b.txt`, the correct output will be `a.txt b.txt`. The other choices either reflect incorrect outputs or misunderstand the nature of the shell script's execution with wildcards and filenames.
Related Questions
View allWhich of the following commands are used to get information on the pro...
The current directory contains the following file: -rwxr-xr-x 1 root...
Which of the following commands will search for the file foo.txt under...
What is true about a recursive directory listing?
Why are web browser cookies considered dangerous?
Related Quizzes
View allNo related quizzes currently available.
- ✓ 500+ Practice Questions
- ✓ Detailed Explanations
- ✓ Progress Analytics
- ✓ Exam Simulations