mirror of
https://github.com/dylanaraps/pure-sh-bible
synced 2024-05-17 21:06:36 +02:00
Merge 97b1534472
into 26bc7e8d6c
This commit is contained in:
commit
8c45f37c71
21
README.md
21
README.md
|
@ -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:**
|
||||
|
|
Loading…
Reference in a new issue