Skip to content

Commit

Permalink
Add Shell Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
chilensis committed Dec 30, 2023
1 parent 54fe965 commit 96926d6
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion shell/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,23 @@ function create_file() {
}
```

### Shell Style Formatting

#### Indentation

Indent 2 spaces. No tabs.

```bash
while read -r f; do
echo "file=${f}"
done < <(find /tmp)
```

#### Line Length and Long Strings

Maximum line length is 80 characters.


#### Meaningful Variable Names

Use uppercase letters for variable names and prefer underscores `_` for readability.
Expand All @@ -89,4 +106,31 @@ OUTPUT_DIR="/path/to/output"
FILE_NAME="example.txt"
```

### Shell Style Formatting
#### Pipelines

If the pipeline doesn't fit all one line, you'll need to split one line per line.

If the pipelines all fit in one line, they should be in one line.

```bash
# All fits on one line
command1 | command2

# Long commands
command1 \
| command2 \
| command3 \
| command4
```

#### Loop

Put `; do` and `; then` on the same line as the while, for or if.

```bash
for dir in "${create_file[@]}"; do
if [[ -d "${dir}/${FileName}" ]]; then
...
fi
done
```

0 comments on commit 96926d6

Please sign in to comment.