0
0
Linux CLIscripting~20 mins

stdin redirection (<) in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Stdin Redirection Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
What is the output of this command using stdin redirection?
Given a file named numbers.txt containing:
1
2
3
What is the output of the command cat < numbers.txt?
A1 2 3
Bnumbers.txt
Ccat: numbers.txt: No such file or directory
D1\n2\n3
Attempts:
2 left
💡 Hint
Think about what cat does when reading from standard input.
💻 Command Output
intermediate
1: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?
Abash: missingfile.txt: No such file or directory
BNo output, command waits for input
Csort: standard input: No such file or directory
Dsort: cannot open missingfile.txt for reading: Permission denied
Attempts:
2 left
💡 Hint
Consider how the shell handles input redirection from a file that does not exist.
📝 Syntax
advanced
1: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?
Awc -l < data.txt
Bwc < -l data.txt
Cwc -l data.txt <
D< wc -l data.txt
Attempts:
2 left
💡 Hint
Remember the syntax for input redirection: command < filename
🚀 Application
advanced
2: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?
A./process.sh input.txt
Bcat input.txt | ./process.sh
C./process.sh < input.txt
D./process.sh > input.txt
Attempts:
2 left
💡 Hint
Think about how stdin redirection works versus passing a filename as an argument.
🧠 Conceptual
expert
2:30remaining
What happens if you combine stdin redirection with a command that also reads a file argument?
Consider the command: grep 'error' < log.txt log2.txt
What will happen?
Agrep searches 'error' in log2.txt and also reads log.txt from stdin
Bgrep searches 'error' only in log2.txt, ignoring stdin
Cgrep searches 'error' in log2.txt and ignores stdin redirection
Dgrep searches 'error' in log.txt twice, once from stdin and once from log2.txt
Attempts:
2 left
💡 Hint
Think about how stdin redirection and file arguments work together in commands.