TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
-c (command) option instructs the Bash executable to read and execute a command string provided as the option-argument to the -c flag, rather than reading commands from standard input or a script file. Once the commands within the string are parsed and executed, the shell process terminates.
Argument Parsing and Positional Parameters
When Bash is invoked with-c, the assignment of positional parameters differs from standard script execution. The non-option arguments (operands) following the command_string are assigned to the shell’s internal variables starting at $0 rather than $1.
command_string: The option-argument containing the literal string of Bash syntax to be evaluated.command_name($0): The first non-option argument following the command string is assigned to$0. This sets the name of the shell or script for the duration of the execution, which dictates how the shell identifies itself in error messages.argument...($1,$2, etc.): Subsequent non-option arguments are assigned to the standard positional parameters.
Execution Mechanics
- Process Creation: Invoking
bash -cspawns a new child Bash process. - String Evaluation: The new shell evaluates the
command_stringexactly as if it were reading a script file. It supports the full Bash grammar, including pipelines, redirections, loops, and conditional statements. - Termination: The exit status of the
bash -cinvocation is the exit status of the last command executed within thecommand_string.
Quote Interpolation and Expansion
Because thecommand_string is typically passed from a parent shell, the quoting mechanism used dictates whether variable expansion occurs in the parent shell or the child shell.
Single Quotes (Child Shell Expansion):
Prevents the parent shell from interpreting variables. The literal string is passed to the child bash process, which then performs the expansion.
bash process. The child shell receives a static string containing the already-evaluated values.
Interaction with Other Flags
The-c operator can be combined with other Bash invocation flags (such as -x for debugging or -e for exiting on error). These flags must precede the command_string option-argument.
Master Bash with Deep Grasping Methodology!Learn More





