Subshells and Command Substitution
$( ) captures a command output. ( ) runs commands in a subshell so changes do not leak out. <( ) feeds output as a file.
Example
x=1
( x=2; echo "inside $x" )
echo "outside $x"
today=$(date +%Y | cut -c1-2)
echo "century prefix $today"
diff <(echo a) <(echo b) | head -3Result
inside 2 outside 1 century prefix 20 1c1 < a ---
Exercise
Capture output.
now=$date)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.