You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/04-redirection.md
+7-2Lines changed: 7 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -608,13 +608,13 @@ Inside our for loop, we create a new name variable. We call the basename functio
608
608
609
609
Why Parentheses `()` ?
610
610
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.
612
612
- **Clarity:** Using `$(...)` is preferred over backticks (`...`) for command substitution because it is more readable and can be nested more easily.
613
613
614
614
Why Curly Braces `{}` ?
615
615
616
616
- **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.
618
618
- **Consistency:** While not always required, using curly braces for variable expansion is a common practice that enhances readability and reduces the risk of errors.
619
619
620
620
* * *
@@ -652,6 +652,10 @@ Inside our for loop, we create a new name variable. We call the basename functio
652
652
> done
653
653
```
654
654
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
+
655
659
!!! dumbbell "Exercise"
656
660
657
661
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
668
672
> done
669
673
```
670
674
675
+
671
676
!!! graduation-cap "keypoints"
672
677
673
678
- `grep` is a powerful search tool with many options for customization.
0 commit comments