010-160 Exam QuestionsBrowse all questions from this exam

010-160 Exam - Question 22


A directory contains the following files:

What would be the output of the following shell script?

for file in *.txt

Show Answer
Correct Answer: E

The provided shell script uses a for loop to iterate over all files in the directory that match the pattern "*.txt". In the directory, there are two files that match this pattern: a.txt and b.txt. The script will print the name of each matching file on a new line. Therefore, the output will include both "a.txt" and "b.txt". The correct answer, reflecting both file names with the correct formatting, is option E.

Discussion

9 comments
Sign in to comment
Nvidia
Feb 24, 2021

I dont understand this question

IanBilbo12
Mar 9, 2021

I believe the shell script calls to echo out the files. However, .cav IS NOT a valid file format, so it doesn't get called??? Anyone who knows for real, please chime in.

NivC
Feb 8, 2022

It is about the wildcard * which means that all files that end with ".txt" are valid, will show in the output the full file name.

rbishunOption: A
Mar 29, 2022

#!/bin/bash for file in *.txt do echo $file done #Output: *.txt

quiquisimoOption: A
Apr 8, 2021

i think it's A because * is a meta-character, so the "for" will search for every pattern that ends with .txt

quiquisimo
Apr 8, 2021

sorry, it's E.

TraianOption: E
Aug 23, 2021

Tested myself. Should be "E" the right answer.

linvidiaOption: E
Oct 27, 2022

Output: a.txt b.txt

VovanichOption: E
Dec 20, 2022

E. a. txt b. txt

JarnBarn
Mar 8, 2024

The formating of this question is bonkers.

rbishunOption: E
Apr 5, 2022

E is the correct answer - script returns same as: ls *.txt

66cf1d7Option: E
Apr 27, 2024

I tested the script myself. If there were no files named that way it iterates through the literal string *.txt and prints each character.