invocation-option
Bash --restricted -c command
Enables restricted-shell rules, including prohibiting cd and certain redirections and variable changes. These restrictions are not a security sandbox; external commands and inherited configuration need independent control. This harmless fixture checks only a prohibited directory change in a disposable child. Run in a fresh private directory with HOME set to that directory and LC_ALL=C. Expected output (one item per line): blocked.
Formal Syntax & Structure
bash syntaxbash
bash --restricted -c commandReturn Value
exit status
See the example and command status; failures are nonzero.
Working Example
Example Snippetbash
bash --noprofile --norc --restricted -c 'if cd .; then exit 1; fi; printf "blocked\n"' 2> diagnostic || exit 1grep -Fq restricted diagnostic || exit 1