Update shell variable syntax in documentation to use ${VAR?} syntax#3306
Update shell variable syntax in documentation to use ${VAR?} syntax#3306copybara-service[bot] merged 1 commit intomainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
b25f057 to
078185a
Compare
|
🤖 Hi @igorts-git, I've received your request, and I'm working on it now! You can track my progress in the logs for more details. |
There was a problem hiding this comment.
This PR consistently updates shell variable syntax in documentation and scripts to use ${VAR?} instead of $VAR to prevent silent failures when variables are unbound. The substitution improves the robustness of the example commands.
🔍 General Feedback
- The changes successfully catch undefined environment variables in bash commands, producing a clear error message instead of failing silently.
- One script (
src/maxtext/examples/sft_train_and_evaluate.py) is missing a closing quote for a bash variable assignment, which will cause a critical syntax error if executed. - A documentation script example has an inline comment before a bash line continuation, breaking the execution block.
- Overall, this is a solid robustness improvement for users copying scripts from the documentation.
| max_prefill_predict_length=$PREDICT_LENGTH # Adjust to fit image tokens + text prompt \ | ||
| max_target_length=$TARGET_LENGTH \ | ||
| max_prefill_predict_length=${PREDICT_LENGTH?} # Adjust to fit image tokens + text prompt \ | ||
| max_target_length=${TARGET_LENGTH?} \ |
There was a problem hiding this comment.
| max_target_length=${TARGET_LENGTH?} \ | |
| max_prefill_predict_length=${PREDICT_LENGTH?} \ |
There was a problem hiding this comment.
This is pseudo-code, I think it is fine to keep as-is. Otherwise it will be less readable.
078185a to
a9cf2c1
Compare
khatwanimohit
left a comment
There was a problem hiding this comment.
can we enforce a check to make sure future PRs also have this syntax.
Gemini suggested this,
#!/bin/bash
# check_env_syntax.sh
# Define excluded variables (Whiteslist)
EXCLUDES="PATH|HOME|PWD|SHELL|USER"
# Search for patterns like $VAR or ${VAR} that DON'T contain '?'
# This looks in .md and .sh files
ERRORS=$(grep -rnE '\$([A-Z_]+|\{[A-Z_]+\})' --include=\*.{md,sh} . | grep -vE "$EXCLUDES" | grep -v '?')
if [ -n "$ERRORS" ]; then
echo "Error: Found raw env variables without the '?' syntax:"
echo "$ERRORS"
exit 1
fi
echo "Env variable syntax check passed."
exit 0
Description
This PR substitutes all code comments and example command lines in the documentation to use a less error-prone syntax.
When an environment variable is not set or misspelled, by default it is replaced with an empty string.
However, shell would fail to run a command if
VARis not set if we use the${VAR?}syntax with the question mark.This helps preventing common issues with using multiple terminal windows and avoids difficult-to-understand error messages.
This PR was vibe-coded with Gemini-CLI. I manually reviewed it and fixed some incorrect cases, such as
${USER_?}somestring, which is supposed to be${USER}_somestring.Tests
N/A. This PR only affects documentation.
I manually ran some commands to validate the syntax.
Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.