This commit is contained in:
Alejandro Cervera 2023-07-28 23:06:33 -05:00 committed by GitHub
commit 8c45f37c71
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -242,6 +242,27 @@ case $var in
esac
```
**Using printf builtin:**
**Example function:**
```sh
startswith() {
if [ "$(printf "%.${#1}s" "$2")" = "$1" ]; then
return 0
else
return 1
fi
}
```
**Example usage:**
```sh
$ startswith 'fo' 'foo'
```
## Check if string ends with sub-string
**Using a case statement:**