File tree 2 files changed +71
-74
lines changed
2 files changed +71
-74
lines changed Original file line number Diff line number Diff line change @@ -77,79 +77,5 @@ rm -f $0
77
77
You need to be careful with the self deletion and ensure that you have your script backed up before you self-delete it.
78
78
79
79
80
- ## Substring in Bash :: Slicing
81
-
82
- Let's review the following example of slicing in a string in Bash:
83
-
84
- ``` bash
85
- #! /bin/bash
86
-
87
- letters=( " A" " B" " C" " D" " E" )
88
- echo ${letters[@]}
89
- ```
90
-
91
- This command will print all the elements of an array.
92
-
93
- Output:
94
-
95
- ``` bash
96
- $ ABCDE
97
- ```
98
-
99
-
100
- Lets see a few more examples:
101
-
102
- - Example 1
103
-
104
- ``` bash
105
- #! /bin/bash
106
-
107
- letters=( " A" " B" " C" " D" " E" )
108
- b=${letters: 0: 2}
109
- echo " ${b} "
110
- ```
111
-
112
- This command wil print array from starting index 0 to 2 where 2 is exclusive.
113
-
114
- ``` bash
115
- $ AB
116
- ```
117
-
118
- - Example 2
119
-
120
- ``` bash
121
- #! /bin/bash
122
-
123
- letters=( " A" " B" " C" " D" " E" )
124
- b=${letters:: 5}
125
- echo " ${b} "
126
- ```
127
-
128
- This command will print from base index 0 to 5, where 5 is exclusive and starting index is default set to 0 .
129
-
130
- ``` bash
131
- $ ABCDE
132
- ```
133
-
134
- - Example 3
135
-
136
- ``` bash
137
- #! /bin/bash
138
-
139
- letters=( " A" " B" " C" " D" " E" )
140
- b=${letters: 3}
141
- echo " ${b} "
142
- ```
143
-
144
- This command will print from starting index
145
- 3 to end of array inclusive .
146
-
147
- ``` bash
148
- $ DE
149
- ```
150
-
151
-
152
-
153
-
154
80
155
81
Original file line number Diff line number Diff line change @@ -39,3 +39,74 @@ echo ${#my_array[@]}
39
39
```
40
40
41
41
Make sure to test this and practice it at your end with different values.
42
+
43
+ ## Substring in Bash :: Slicing
44
+
45
+ Let's review the following example of slicing in a string in Bash:
46
+
47
+ ``` bash
48
+ #! /bin/bash
49
+
50
+ letters=( " A" " B" " C" " D" " E" )
51
+ echo ${letters[@]}
52
+ ```
53
+
54
+ This command will print all the elements of an array.
55
+
56
+ Output:
57
+
58
+ ``` bash
59
+ $ ABCDE
60
+ ```
61
+
62
+
63
+ Lets see a few more examples:
64
+
65
+ - Example 1
66
+
67
+ ``` bash
68
+ #! /bin/bash
69
+
70
+ letters=( " A" " B" " C" " D" " E" )
71
+ b=${letters: 0: 2}
72
+ echo " ${b} "
73
+ ```
74
+
75
+ This command wil print array from starting index 0 to 2 where 2 is exclusive.
76
+
77
+ ``` bash
78
+ $ AB
79
+ ```
80
+
81
+ - Example 2
82
+
83
+ ``` bash
84
+ #! /bin/bash
85
+
86
+ letters=( " A" " B" " C" " D" " E" )
87
+ b=${letters:: 5}
88
+ echo " ${b} "
89
+ ```
90
+
91
+ This command will print from base index 0 to 5, where 5 is exclusive and starting index is default set to 0 .
92
+
93
+ ``` bash
94
+ $ ABCDE
95
+ ```
96
+
97
+ - Example 3
98
+
99
+ ``` bash
100
+ #! /bin/bash
101
+
102
+ letters=( " A" " B" " C" " D" " E" )
103
+ b=${letters: 3}
104
+ echo " ${b} "
105
+ ```
106
+
107
+ This command will print from starting index
108
+ 3 to end of array inclusive .
109
+
110
+ ``` bash
111
+ $ DE
112
+ ```
You can’t perform that action at this time.
0 commit comments