Challenge - 5 Problems
Process Substitution Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this process substitution command?
Consider the following bash command using process substitution. What will it output?
Bash Scripting
diff <(echo -e "apple\nbanana") <(echo -e "apple\nbanana\ncherry")
Attempts:
2 left
💡 Hint
Process substitution creates temporary files from command outputs for diff to compare.
✗ Incorrect
The first input has two lines: apple and banana. The second input has three lines: apple, banana, and cherry. The diff command shows that after line 2 in the first input, line 3 (cherry) is added in the second input.
📝 Syntax
intermediate2:00remaining
Which option correctly uses process substitution to sort two files and compare them?
You want to compare the sorted contents of file1.txt and file2.txt using diff and process substitution. Which command is correct?
Attempts:
2 left
💡 Hint
Process substitution uses <() to provide command output as a file input.
✗ Incorrect
Option D correctly uses <() to run sort on each file and pass the outputs as temporary files to diff. Option D uses >() which is for output redirection, not input. Option D tries to pipe a filename, which is invalid. Option D uses unnecessary input redirection inside process substitution.
🔧 Debug
advanced2:00remaining
Why does this process substitution command fail?
You run this command and get an error: 'bash: syntax error near unexpected token `>'':
cat >(grep foo > output.txt)
Why does it fail?
Attempts:
2 left
💡 Hint
Think about what >() does and how cat expects its arguments.
✗ Incorrect
The >() syntax creates a named pipe for output redirection. Using it as an argument to cat is invalid because cat expects input files or stdin, not output pipes. This causes a syntax error.
🚀 Application
advanced2:00remaining
How to merge two sorted lists using process substitution?
You have two sorted files, list1.txt and list2.txt. You want to merge them into one sorted output using the 'sort -m' command and process substitution. Which command achieves this?
Attempts:
2 left
💡 Hint
Process substitution can provide command outputs as files to commands expecting file arguments.
✗ Incorrect
Option B uses process substitution to provide the contents of each file as inputs to 'sort -m', which merges sorted inputs. Option B merges files directly but does not guarantee they are sorted first. Option B misuses >() which is for output redirection. Option B unnecessarily sorts already sorted files again.
🧠 Conceptual
expert2:00remaining
What is the main difference between <() and >() in bash process substitution?
Choose the best explanation of the difference between <() and >() in bash process substitution.
Attempts:
2 left
💡 Hint
Think about which one creates a readable file and which one creates a writable file.
✗ Incorrect
<() runs a command and provides its output as a readable file (input) to another command. >() creates a writable file (like a named pipe) that a command can write into. They serve opposite purposes in process substitution.