A directory contains the following files:
What would be the output of the following shell script?
for file in *.txt
A directory contains the following files:
What would be the output of the following shell script?
for file in *.txt
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.
I dont understand this question
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.
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.
#!/bin/bash for file in *.txt do echo $file done #Output: *.txt
The formating of this question is bonkers.
E. a. txt b. txt
Output: a.txt b.txt
Tested myself. Should be "E" the right answer.
i think it's A because * is a meta-character, so the "for" will search for every pattern that ends with .txt
sorry, it's E.
I tested the script myself. If there were no files named that way it iterates through the literal string *.txt and prints each character.
E is the correct answer - script returns same as: ls *.txt