Bash Substring – Syntax and Examples

Bash Substring

In this Bash Tutorial, we shall learn to compute substring of a string given starting position and length of substring.

Syntax

To find substring in bash, use the following syntax :

Providing length is optional. If length is not specified, end of the string is considered end of the substring.

 

Example – Compute substring provided position and length of substring

Bash Script File

 

Example – Compute substring provided position

Bash Script File

End of string is considered as end of substring.