Autosave: 2023-02-24 07:42:55

This commit is contained in:
thomasabishop 2023-02-24 07:42:55 +00:00
parent 2bbd42f5de
commit e8b832f160
2 changed files with 40 additions and 0 deletions

View file

@ -0,0 +1,30 @@
---
categories:
- Programming Languages
tags:
- shell
- data-types
---
# Strings in bash
## Return a substring by index
```bash
myString="hello"
substring=${myString:0:3}
# hel
```
This is often used when looping through each character in a string.
## Loop through each character in a string
```bash
str="hallelujah"
stringLength=$(expr length str)
for (( i=0; i<=${stringLength}; i++ )); do
echo "${str:$i:1}"
done
```

View file

@ -0,0 +1,10 @@
---
categories:
- Programming Languages
tags:
- shell
---
# Substrings in Bash