Simple and compound commands
A simple command can include assignments, a command name, arguments and redirections. An assignment alone changes shell state; a temporary assignment before an ordinary external command supplies an environment value for that invocation. Lists sequence commands with semicolons or newlines, or use && and || to make execution conditional. A brace group { list; } executes in the current shell when used on its own; parentheses ( list ) isolate shell state in a subshell. Both support redirection of the entire group and normally return the status of the last command executed. Braces are reserved words: include spaces and a terminating semicolon or newline. A trailing & starts an asynchronous list; use wait on the saved $! to obtain its completion status. Do not assume every command launches a new process. A subshell isolates shell variables and working directory, not filesystem changes. An asynchronous list has an immediate launch status of zero in the ordinary successful launch case, which is not the eventual child result. In the background example the final printf succeeds after displaying the saved child status, so the enclosing script itself returns zero on the demonstrated path.
Practical examples
Run each example as a separate script in a fresh noninteractive Bash 5.2 process and empty practice directory. Tests use C locale; do not enter expected output as code.
Compare groups
value=outer{ value=brace; }printf '%s\n' "$value"( value=paren; printf '%s\n' "$value" )printf '%s\n' "$value"Expected stdout:
braceparenbraceThe standalone brace group changes the parent; the parentheses do not.
Temporary environment and grouped output
mode=outer{ mode=child bash -c 'printf "%s\n" "$mode"'; printf '%s\n' "$mode"; } > group.txtcat group.txtExpected stdout:
childouterThe assignment for the external Bash is temporary, and both outputs go into one file.
Wait for a bounded background task
( printf 'work\n'; exit 4 ) > work.txt &pid=$!wait "$pid"status=$?cat work.txtprintf 'status=%s\n' "$status"Expected stdout:
workstatus=4The saved PID identifies the asynchronous job; waiting observes completion before reading the file.
Common mistakes
Do not confuse grouping braces with brace expansion. A brace group inside a pipeline may run in a subshell; the current-shell rule is for a standalone group.
Practice
Predict the value of a counter after a brace group and a parenthesized group. Then redirect two printf calls as a unit into a new practice file and check it.
Next: Command resolution and hashing