Skip to content

Commit 9f7c11b

Browse files
update for loop
1 parent 5762c13 commit 9f7c11b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

docs/04-redirection.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,13 +608,13 @@ Inside our for loop, we create a new name variable. We call the basename functio
608608

609609
Why Parentheses `()` ?
610610

611-
- **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.
611+
- **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.
612612
- **Clarity:** Using `$(...)` is preferred over backticks (`...`) for command substitution because it is more readable and can be nested more easily.
613613

614614
Why Curly Braces `{}` ?
615615

616616
- **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.
617-
- **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.
617+
- **Disambiguation:** For example, if you had a variable named `filename_suffix`, writing `$filename_suffix` could lead to ,especially if you are trying to concatenate or manipulate it with other strings. Using `${filename}` makes it clear where the variable name ends.
618618
- **Consistency:** While not always required, using curly braces for variable expansion is a common practice that enhances readability and reduces the risk of errors.
619619

620620
* * *
@@ -652,6 +652,10 @@ Inside our for loop, we create a new name variable. We call the basename functio
652652
> done
653653
```
654654

655+
- `mv ${filename} ${name}_2019.txt:`This line renames the file.
656+
- `${filename}` is the original file name.
657+
- `${name}_2019.txt` is the new file name, which consists of the original name (without .txt), followed by "_2019.txt".
658+
655659
!!! dumbbell "Exercise"
656660

657661
Remove `_2019` from all of the `.txt` files.
@@ -668,6 +672,7 @@ Inside our for loop, we create a new name variable. We call the basename functio
668672
> done
669673
```
670674

675+
671676
!!! graduation-cap "keypoints"
672677

673678
- `grep` is a powerful search tool with many options for customization.

0 commit comments

Comments
 (0)