processes

I once wrote cd /tmp inside a pipeline and wondered why the next line was still in the old directory Pipelines run in subshells The cd happened somewhere else

Chains

true && printf 'ok\n'
false || printf 'fallback\n'

&& runs the next command on success || runs it on failure Chain them for compact guards , do not chain five of them into a puzzle

Subshells

( cd /tmp && pwd )

Parentheses create a child shell Changes inside do not escape Use braces { } when you need the changes to stick in the current shell

Background

sleep 1 &
wait

& sends a job to the background wait pauses until it finishes A script that exits while children run leaves a mess behind

Signals

kill -TERM <pid> asks a process to stop kill -KILL <pid> removes the negotiation Use the polite one first

Next

Put it all into a file in 09 scripts

Posted