Skip to content

Commit

Permalink
update variable expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
DininduSenanayake committed Jul 30, 2024
1 parent d4d126b commit 3e368c7
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions docs/04-redirection.md
Original file line number Diff line number Diff line change
Expand Up @@ -593,16 +593,16 @@ Inside our for loop, we create a new name variable. We call the basename functio
> done
```

Parentheses `()`
Why Parentheses `()` ?

- Command Substitution: The `$(...)` syntax is used for command substitution. It allows you to execute a command and use its output as a value in your script. In this case, $(basename ${filename} .fastq) executes the basename command and captures its output, which is then assigned to the variable name.
- Clarity: Using `$(...)` is preferred over backticks (`...`) for command substitution because it is more readable and can be nested more easily.
- **Command Substitution:** The `$(...)` syntax is used for command substitution. It allows you to execute a command and use its output as a value in your script. In this case, $(basename ${filename} .fastq) executes the basename command and captures its output, which is then assigned to the variable name.
- **Clarity:** Using `$(...)` is preferred over backticks (`...`) for command substitution because it is more readable and can be nested more easily.

Curly Braces {}
Why Curly Braces `{}` ?

- Variable Expansion: The `${filename}` syntax is used to clearly indicate that you are referencing the variable `filename`. This is particularly useful in cases where the variable name might be adjacent to other characters that could be interpreted as part of the variable name.
- Disambiguation: For example, if you had a variable named `filename_suffix`, writing `$filename_suffi`x could lead to confusion if you were trying to concatenate or manipulate it with other strings. Using `${filename}` makes it clear where the variable name ends.
- Consistency: While not always required, using curly braces for variable expansion is a common practice that enhances readability and reduces the risk of errors.
- **Variable Expansion:** The `${filename}` syntax is used to clearly indicate that you are referencing the variable `filename`. This is particularly useful in cases where the variable name might be adjacent to other characters that could be interpreted as part of the variable name.
- **Disambiguation:** For example, if you had a variable named `filename_suffix`, writing `$filename_suffi`x could lead to confusion if you were trying to concatenate or manipulate it with other strings. Using `${filename}` makes it clear where the variable name ends.
- **Consistency:** While not always required, using curly braces for variable expansion is a common practice that enhances readability and reduces the risk of errors.

!!! dumbbell "Exercise"

Expand Down

0 comments on commit 3e368c7

Please sign in to comment.