In the current interactive Bash, make gs expand to git status.
Pass the replacement containing a space as one alias definition.
Which command is appropriate?
Quote an alias replacement containing spaces so NAME=value is passed as one argument. The command is not executed while the alias is defined.
Detailed explanation
alias gs=git statusIncorrect. status becomes a separate argument instead of part of the replacement.
alias gs='git status'Correct. Quoting keeps git status together as the alias replacement.
alias 'gs=git' statusIncorrect. It does not define the requested replacement.
alias gs $(git status)Incorrect. It executes git status while defining the alias.
Try it yourself
An example you can run in a temporary verification environment.
bash --noprofile --norc -ic "alias gs='printf alias-quoted\\n'; alias gs"Expected result
gsのalias定義を表示Key points
- Quote values containing spaces
- Definition does not execute the command
- Use alias NAME=value
Notes
- Environment: GNU Bash 5.2 / 一時対話シェル
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Alias definition
Registration of a name and the text to which that name expands.
Single quotes
Quoting that keeps spaces and metacharacters as literal text.
Word splitting
Turning unquoted expanded whitespace into boundaries between shell arguments.