Run ./deploy.sh staging.
Refer to staging inside the script.
Which special parameter should be used?
$1 is the first positional argument and should normally be quoted when expanded.
Detailed explanation
$0Incorrect. $0 normally represents the script or shell name.
Incorrect. $0 normally represents the script or shell name.
$#Incorrect. $# is the number of positional parameters.
Incorrect. $# is the number of positional parameters.
$1Correct. $1 contains the first argument, staging.
Correct. $1 contains the first argument, staging.
$@Incorrect. $@ expands all positional parameters.
Incorrect. $@ expands all positional parameters.
Try it yourself
An example you can run in a temporary verification environment.
bash --noprofile --norc -c 'printf "%s\n" "$1"' deploy.sh stagingExpected result
stagingKey points
- $0 is the script name
- $1 starts positional arguments
- Quote expansions
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
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.