Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Add function to find substring at the beginning of a string #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:**
Expand Down