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 allWhere is the operating system of a Raspberry Pi stored?
Why are web browser cookies considered dangerous?
What is true about the dmesg command? (Choose TWO correct answers.)
Which of the following types of bus can connect hard disk drives with...
Which of the following commands sorts the output of the command export...
Related Quizzes
View allNo related quizzes currently available.
- ✓ 500+ Practice Questions
- ✓ Detailed Explanations
- ✓ Progress Analytics
- ✓ Exam Simulations