Skip to content

Instantly share code, notes, and snippets.

@alucard001
Last active May 23, 2025 10:24
Show Gist options
  • Save alucard001/97ad95d12a0ec706e6aa8dd55a4a9c67 to your computer and use it in GitHub Desktop.
Save alucard001/97ad95d12a0ec706e6aa8dd55a4a9c67 to your computer and use it in GitHub Desktop.
Given a section of CICD pipeline in Gitlab, what is the difference between `${vProj2}` and `$vProj2`?
# In a GitLab CI/CD pipeline (and in shell scripting), both `$vProj2` and `${vProj2}` are used for variable expansion,
# but there is a subtle difference:
# - **`$vProj2`**: Expands the variable `vProj2`. This is the simplest form and works when the variable name is immediately
# followed by a character that cannot be part of a variable name (like a space or punctuation).
# - **`${vProj2}`**: Also expands the variable `vProj2`, but the braces are used to clearly delimit the variable name.
# This is especially useful when you want to append characters directly after the variable name, e.g., `${vProj2}_suffix`,
# or when the variable name is followed by a character that could be interpreted as part of the name.
# **Summary:**
# - Use `$vProj2` for simple cases.
# - Use `${vProj2}` when the variable name needs to be clearly separated from surrounding text or when appending characters
# immediately after the variable.
# Both forms are valid and expand to the value of `vProj2`, but braces provide clarity and prevent ambiguity
# in more complex expressions.
variables:
vProj2: myvproject2
before_script:
- export PROJECT2=${vProj2}
- echo $PROJECT2 # return myvproject2
- echo ${PROJECT2} # return myvproject2
- export PROJECT3=$vProj2
- echo $PROJECT3 # return myvproject2
- echo ${PROJECT3} # return myvproject2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment