Skip to content

Commit

Permalink
Update convention for shell variable names (#11)
Browse files Browse the repository at this point in the history
Resolves #5

This PR updates our convention for shell variable names to explicitly
mention the case of non-constant variables.

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/style-guides/11"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
  • Loading branch information
jdeanwallace authored Jun 19, 2023
1 parent e68d7f7 commit 824bb4c
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,30 @@ TIMEOUT_SECONDS=5

### Variable names

Variable names should be all uppercase.
Constant variables and exported environment variables should be uppercase.

```bash
WELCOME_MESSAGE="Hello, world!"
readonly WELCOME_MESSAGE='Hello, world!'
```

```bash
for URL in "${URLS[@]}"; do
wget "${URL}"
WELCOME_MESSAGE="$(echo 'Hello, World!')"
readonly WELCOME_MESSAGE
export WELCOME_MESSAGE
```

```bash
print() {
local -r MESSAGE=$1
echo "${MESSAGE}"
}
```

Non-constant variables, such as the ones in loops, should be lowercase.

```bash
for value in 1 2 3; do
echo "Hello ${value} times"
done
```

Expand Down

0 comments on commit 824bb4c

Please sign in to comment.