Challenge - 5 Problems
Stdin Redirection Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate1:30remaining
What is the output of this command using stdin redirection?
Given a file named
1
2
3
What is the output of the command
numbers.txt containing:1
2
3
What is the output of the command
cat < numbers.txt?Attempts:
2 left
💡 Hint
Think about what
cat does when reading from standard input.✗ Incorrect
The command
cat < numbers.txt reads the contents of numbers.txt through stdin and outputs the lines as they are, each on its own line.💻 Command Output
intermediate1:30remaining
What error occurs when redirecting stdin from a non-existent file?
What happens when you run
sort < missingfile.txt if missingfile.txt does not exist?Attempts:
2 left
💡 Hint
Consider how the shell handles input redirection from a file that does not exist.
✗ Incorrect
The shell tries to open the file before running the command. If the file does not exist, the shell reports an error like 'No such file or directory'.
📝 Syntax
advanced1:30remaining
Which command correctly uses stdin redirection to count lines in a file?
You want to count the number of lines in
data.txt using wc -l and stdin redirection. Which command is correct?Attempts:
2 left
💡 Hint
Remember the syntax for input redirection: command < filename
✗ Incorrect
The correct syntax places the redirection operator after the command and before the filename:
wc -l < data.txt reads data.txt as stdin for wc -l.🚀 Application
advanced2:00remaining
How to use stdin redirection with a script that reads input?
You have a script
process.sh that reads lines from standard input. Which command correctly feeds input.txt to the script using stdin redirection?Attempts:
2 left
💡 Hint
Think about how stdin redirection works versus passing a filename as an argument.
✗ Incorrect
Using
< input.txt sends the file content as standard input to the script. Option C works but uses a pipe, not stdin redirection. Option C passes filename as argument, not stdin. Option C redirects output, not input.🧠 Conceptual
expert2:30remaining
What happens if you combine stdin redirection with a command that also reads a file argument?
Consider the command:
What will happen?
grep 'error' < log.txt log2.txtWhat will happen?
Attempts:
2 left
💡 Hint
Think about how stdin redirection and file arguments work together in commands.
✗ Incorrect
The shell redirects stdin from
log.txt, but since log2.txt is provided as a file argument, grep reads only from log2.txt and ignores standard input.