0
0
Bash Scriptingscripting~20 mins

Process substitution (<() and >()) in Bash Scripting - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Process Substitution Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2: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")
A2a3\n> cherry
B1a2\n> banana
CNo output (files are identical)
DSyntax error
Attempts:
2 left
💡 Hint
Process substitution creates temporary files from command outputs for diff to compare.
📝 Syntax
intermediate
2: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?
Adiff <(sort < file1.txt) <(sort < file2.txt)
Bdiff >(sort file1.txt) >(sort file2.txt)
Cdiff <(file1.txt | sort) <(file2.txt | sort)
Ddiff <(sort file1.txt) <(sort file2.txt)
Attempts:
2 left
💡 Hint
Process substitution uses <() to provide command output as a file input.
🔧 Debug
advanced
2: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?
ABecause >() is for output redirection and cannot be used as an argument to cat
BBecause grep cannot write to output.txt inside process substitution
CBecause cat requires input files, not output redirection
DBecause process substitution only works with <(), not >()
Attempts:
2 left
💡 Hint
Think about what >() does and how cat expects its arguments.
🚀 Application
advanced
2: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?
Asort -m list1.txt list2.txt
Bsort -m <(cat list1.txt) <(cat list2.txt)
Csort -m >(cat list1.txt) >(cat list2.txt)
Dsort -m <(sort list1.txt) <(sort list2.txt)
Attempts:
2 left
💡 Hint
Process substitution can provide command outputs as files to commands expecting file arguments.
🧠 Conceptual
expert
2: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.
A<() redirects output to a file; >() reads input from a file
B<() and >() are interchangeable and both provide command output as input
C<() provides the output of a command as a file input; >() provides a writable file to send data into a command
D<() is used only for input files; >() is used only for output files but not with commands
Attempts:
2 left
💡 Hint
Think about which one creates a readable file and which one creates a writable file.